diff options
author | Sven Gothel <[email protected]> | 2023-10-22 08:02:13 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-10-22 08:02:13 +0200 |
commit | 67c7f0f78e2f06b592e083b2c2de9fa7bc7b9cc9 (patch) | |
tree | 60dc086c9c6c0c2235c408d3de928f3ddb9e2cb0 | |
parent | 116ce8e5a4672b963a4b2bbb2054158a77f8417b (diff) |
Sync Java with C++ and tag API changes; All trial unit tests passed
API Changes for v3.2.0:
- BTAdapter:
- setPrivacy(bool) added
- initialize() w/o args or default args removed
- initialize(final BTMode btMode, boolean powerOn) added
-rw-r--r-- | api/direct_bt/BTAdapter.hpp | 12 | ||||
-rw-r--r-- | api/direct_bt/BTManager.hpp | 1 | ||||
-rw-r--r-- | examples/dbt_peripheral00.cpp | 13 | ||||
-rw-r--r-- | examples/dbt_repeater00.cpp | 15 | ||||
-rw-r--r-- | examples/dbt_scanner10.cpp | 13 | ||||
-rw-r--r-- | examples/java/DBTPeripheral00.java | 12 | ||||
-rw-r--r-- | examples/java/DBTScanner10.java | 2 | ||||
-rw-r--r-- | java/jau/direct_bt/DBTAdapter.java | 17 | ||||
-rw-r--r-- | java/jni/direct_bt/DBTAdapter.cxx | 18 | ||||
-rw-r--r-- | java/org/direct_bt/BTAdapter.java | 37 | ||||
-rw-r--r-- | src/direct_bt/BTAdapter.cpp | 20 | ||||
-rw-r--r-- | trial/direct_bt/dbt_client01.hpp | 13 | ||||
-rw-r--r-- | trial/direct_bt/dbt_server01.hpp | 13 | ||||
-rw-r--r-- | trial/java/trial/org/direct_bt/DBTClient01.java | 12 | ||||
-rw-r--r-- | trial/java/trial/org/direct_bt/DBTServer01.java | 12 |
15 files changed, 110 insertions, 100 deletions
diff --git a/api/direct_bt/BTAdapter.hpp b/api/direct_bt/BTAdapter.hpp index 308f2457..d483c18c 100644 --- a/api/direct_bt/BTAdapter.hpp +++ b/api/direct_bt/BTAdapter.hpp @@ -747,6 +747,12 @@ namespace direct_bt { */ bool setPowered(const bool power_on) noexcept; + /** + * Toggle adapter privacy address mode, i.e. resolvable random address including IRK. + * @param enable toggle to enable or disable (default) + * @return HCIStatusCode::SUCCESS or an error state on failure + * @since 3.2.0 + */ HCIStatusCode setPrivacy(const bool enable) noexcept; /** @@ -866,15 +872,15 @@ namespace direct_bt { * Calling the method will allow close() to power-off the adapter, * if not powered on before. * </p> - * @param btMode the desired adapter's BTMode, defaults to BTMode::DUAL + * @param btMode the desired adapter's BTMode, default is BTMode::DUAL * @param powerOn true to leave adapter powered-on (default), otherwise leave it off * * @return HCIStatusCode::SUCCESS or an error state on failure (e.g. power-on) * @see isInitialized() * @see close() * @see setPowered() - * @since 2.4.0 + * @since 3.2.0 */ - HCIStatusCode initialize(const BTMode btMode=BTMode::DUAL, const bool powerOn=true) noexcept; + HCIStatusCode initialize(const BTMode btMode, const bool powerOn) noexcept; /** * Returns true, if initialize() has already been called for this adapter, otherwise false. diff --git a/api/direct_bt/BTManager.hpp b/api/direct_bt/BTManager.hpp index 3a80621b..43ee4979 100644 --- a/api/direct_bt/BTManager.hpp +++ b/api/direct_bt/BTManager.hpp @@ -416,6 +416,7 @@ namespace direct_bt { * @param btMode the desired adapter's BTMode * @param powerOn true to leave adapter powered-on, otherwise leave it off * @return HCIStatusCode::SUCCESS or an error state on failure (e.g. power-on) + * @since 3.2.0 */ HCIStatusCode initializeAdapter(AdapterInfo& adapterInfo, const uint16_t dev_id, const BTMode btMode, const bool powerOn) noexcept; diff --git a/examples/dbt_peripheral00.cpp b/examples/dbt_peripheral00.cpp index ff83084c..ca078395 100644 --- a/examples/dbt_peripheral00.cpp +++ b/examples/dbt_peripheral00.cpp @@ -613,20 +613,20 @@ static bool initAdapter(std::shared_ptr<BTAdapter>& adapter) { } if( !adapter->isInitialized() ) { // Initialize with defaults and power-on - const HCIStatusCode status = adapter->initialize( btMode ); + const HCIStatusCode status = adapter->initialize( btMode, false ); if( HCIStatusCode::SUCCESS != status ) { fprintf_td(stderr, "initAdapter: initialize failed: %s: %s\n", to_string(status).c_str(), adapter->toString().c_str()); return false; } - } else if( !adapter->setPowered( true ) ) { - fprintf_td(stderr, "initAdapter: setPower.1 on failed: %s\n", adapter->toString().c_str()); + } else if( !adapter->setPowered( false ) ) { + fprintf_td(stderr, "initAdapter: setPower.1 off failed: %s\n", adapter->toString().c_str()); return false; } - // adapter is powered-on + // adapter is powered-off fprintf_td(stderr, "initAdapter.1: %s\n", adapter->toString().c_str()); - if( adapter->setPowered(false) ) { + { HCIStatusCode status = adapter->setName(adapter_name, adapter_short_name); if( HCIStatusCode::SUCCESS == status ) { fprintf_td(stderr, "initAdapter: setLocalName OK: %s\n", adapter->toString().c_str()); @@ -661,9 +661,6 @@ static bool initAdapter(std::shared_ptr<BTAdapter>& adapter) { fprintf_td(stderr, "initAdapter: setPower.2 on failed: %s\n", adapter->toString().c_str()); return false; } - } else { - fprintf_td(stderr, "initAdapter: setPowered.2 off failed: %s\n", adapter->toString().c_str()); - return false; } fprintf_td(stderr, "initAdapter.2: %s\n", adapter->toString().c_str()); diff --git a/examples/dbt_repeater00.cpp b/examples/dbt_repeater00.cpp index b39adb85..f9e8d22a 100644 --- a/examples/dbt_repeater00.cpp +++ b/examples/dbt_repeater00.cpp @@ -536,7 +536,7 @@ static bool initAdapterToServer(std::shared_ptr<BTAdapter>& adapter) { } // Initialize with defaults and power-on if( !adapter->isInitialized() ) { - HCIStatusCode status = adapter->initialize( btMode ); + HCIStatusCode status = adapter->initialize( btMode, true ); if( HCIStatusCode::SUCCESS != status ) { fprintf_td(stderr, "initAdapterToServer: Adapter initialization failed: %s: %s\n", to_string(status).c_str(), adapter->toString().c_str()); @@ -768,20 +768,20 @@ static bool initAdapterToClient(std::shared_ptr<BTAdapter>& adapter) { } if( !adapter->isInitialized() ) { // Initialize with defaults and power-on - const HCIStatusCode status = adapter->initialize( btMode ); + const HCIStatusCode status = adapter->initialize( btMode, false ); if( HCIStatusCode::SUCCESS != status ) { fprintf_td(stderr, "initAdapterToClient: initialize failed: %s: %s\n", to_string(status).c_str(), adapter->toString().c_str()); return false; } - } else if( !adapter->setPowered( true ) ) { - fprintf_td(stderr, "initAdapterToClient: setPower.1 on failed: %s\n", adapter->toString().c_str()); + } else if( !adapter->setPowered( false ) ) { + fprintf_td(stderr, "initAdapterToClient: setPower.1 off failed: %s\n", adapter->toString().c_str()); return false; } - // adapter is powered-on + // adapter is powered-off fprintf_td(stderr, "initAdapterToClient.1: %s\n", adapter->toString().c_str()); - if( adapter->setPowered(false) ) { + { HCIStatusCode status = adapter->setName(adapterToClientName, adapterToClientShortName); if( HCIStatusCode::SUCCESS == status ) { fprintf_td(stderr, "initAdapterToClient: setLocalName OK: %s\n", adapter->toString().c_str()); @@ -816,9 +816,6 @@ static bool initAdapterToClient(std::shared_ptr<BTAdapter>& adapter) { fprintf_td(stderr, "initAdapterToClient: setPower.2 on failed: %s\n", adapter->toString().c_str()); return false; } - } else { - fprintf_td(stderr, "initAdapterToClient: setPowered.2 off failed: %s\n", adapter->toString().c_str()); - return false; } fprintf_td(stderr, "initAdapterToClient.2: %s\n", adapter->toString().c_str()); diff --git a/examples/dbt_scanner10.cpp b/examples/dbt_scanner10.cpp index 15c4ddd0..20faf44a 100644 --- a/examples/dbt_scanner10.cpp +++ b/examples/dbt_scanner10.cpp @@ -134,8 +134,8 @@ static bool GATT_PING_ENABLED = false; static bool REMOVE_DEVICE = true; // Default from dbt_peripheral00.cpp or DBTPeripheral00.java -static std::unique_ptr<uuid_t> cmd_uuid = jau::uuid_t::create(std::string("d0ca6bf3-3d52-4760-98e5-fc5883e93712")); -static std::unique_ptr<uuid_t> cmd_rsp_uuid = jau::uuid_t::create(std::string("d0ca6bf3-3d53-4760-98e5-fc5883e93712")); +static std::unique_ptr<uuid_t> cmd_uuid = nullptr; // jau::uuid_t::create(std::string("d0ca6bf3-3d52-4760-98e5-fc5883e93712")); +static std::unique_ptr<uuid_t> cmd_rsp_uuid = nullptr; // jau::uuid_t::create(std::string("d0ca6bf3-3d53-4760-98e5-fc5883e93712")); static uint8_t cmd_arg = 0x44; static bool SHOW_UPDATE_EVENTS = false; @@ -439,6 +439,15 @@ static void processReadyDevice(const BTDeviceRef& device) { fprintf_td(stderr, "****** Processing Ready Device: getServices() failed %s\n", device->toString().c_str()); goto exit; } + { + const BTSecurityRegistry::Entry* sec = BTSecurityRegistry::getStartOf(device->getAddressAndType().address, device->getName()); + if( nullptr != sec && sec->getPairingPasskey() != BTSecurityRegistry::Entry::NO_PASSKEY ) { + char pin[6+1]; + snprintf(pin, sizeof(pin), "%06u", static_cast<uint32_t>( sec->getPairingPasskey() )%1000000_u32 ); + // device->setPairingPasskey( static_cast<uint32_t>( sec->getPairingPasskey() ) ); + device->setPairingPINCode( pin ); + } + } const uint64_t t5 = jau::getCurrentMilliseconds(); { diff --git a/examples/java/DBTPeripheral00.java b/examples/java/DBTPeripheral00.java index 107bf7a5..05ce66e6 100644 --- a/examples/java/DBTPeripheral00.java +++ b/examples/java/DBTPeripheral00.java @@ -654,20 +654,20 @@ public class DBTPeripheral00 { } if( !adapter.isInitialized() ) { // Initialize with defaults and power-on - final HCIStatusCode status = adapter.initialize( btMode ); + final HCIStatusCode status = adapter.initialize( btMode, false ); if( HCIStatusCode.SUCCESS != status ) { PrintUtil.fprintf_td(System.err, "initAdapter: initialization failed: %s: %s\n", status.toString(), adapter.toString()); return false; } - } else if( !adapter.setPowered( true ) ) { - PrintUtil.fprintf_td(System.err, "initAdapter: setPower.1 on failed: %s\n", adapter.toString()); + } else if( !adapter.setPowered( false ) ) { + PrintUtil.fprintf_td(System.err, "initAdapter: setPower.1 off failed: %s\n", adapter.toString()); return false; } - // adapter is powered-on + // adapter is powered-off PrintUtil.println(System.err, "initAdapter.1: "+adapter.toString()); - if( adapter.setPowered(false) ) { + { HCIStatusCode status = adapter.setName(adapter_name, adapter_short_name); if( HCIStatusCode.SUCCESS == status ) { PrintUtil.fprintf_td(System.err, "initAdapter: setLocalName OK: %s\n", adapter.toString()); @@ -702,8 +702,6 @@ public class DBTPeripheral00 { PrintUtil.fprintf_td(System.err, "initAdapter: setPower.2 on failed: %s\n", adapter.toString()); return false; } - } else { - PrintUtil.fprintf_td(System.err, "initAdapter: setPowered.2 off failed: %s\n", adapter.toString()); } PrintUtil.println(System.err, "initAdapter.2: "+adapter.toString()); diff --git a/examples/java/DBTScanner10.java b/examples/java/DBTScanner10.java index c36f3643..f55616e2 100644 --- a/examples/java/DBTScanner10.java +++ b/examples/java/DBTScanner10.java @@ -608,7 +608,7 @@ public class DBTScanner10 { } // Initialize with defaults and power-on if( !adapter.isInitialized() ) { - final HCIStatusCode status = adapter.initialize( btMode ); + final HCIStatusCode status = adapter.initialize( btMode, true ); if( HCIStatusCode.SUCCESS != status ) { PrintUtil.fprintf_td(System.err, "initAdapter: Adapter initialization failed: %s: %s\n", status.toString(), adapter.toString()); diff --git a/java/jau/direct_bt/DBTAdapter.java b/java/jau/direct_bt/DBTAdapter.java index ec30efe1..78f40d4f 100644 --- a/java/jau/direct_bt/DBTAdapter.java +++ b/java/jau/direct_bt/DBTAdapter.java @@ -283,6 +283,12 @@ public class DBTAdapter extends DBTObject implements BTAdapter public final native boolean setPowered(final boolean power_on); @Override + public final HCIStatusCode setPrivacy(final boolean enable) { + return HCIStatusCode.get( setPrivacyImpl( enable ) ); + } + private native byte setPrivacyImpl(boolean enable); + + @Override public final native boolean getSecureConnectionsEnabled(); @Override @@ -310,15 +316,10 @@ public class DBTAdapter extends DBTObject implements BTAdapter public final native void setSMPKeyPath(final String path); @Override - public final HCIStatusCode initialize() { - return initialize(BTMode.DUAL); - } - - @Override - public final HCIStatusCode initialize(final BTMode btMode) { - return HCIStatusCode.get( initializeImpl(btMode.value) ); + public final HCIStatusCode initialize(final BTMode btMode, final boolean powerOn) { + return HCIStatusCode.get( initializeImpl(btMode.value, powerOn) ); } - private native byte initializeImpl(final byte btModeInt); + private native byte initializeImpl(final byte btModeInt, final boolean powerOn); @Override public final native boolean isInitialized(); diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx index 8022b92e..0e0062d2 100644 --- a/java/jni/direct_bt/DBTAdapter.cxx +++ b/java/jni/direct_bt/DBTAdapter.cxx @@ -913,6 +913,20 @@ jboolean Java_jau_direct_1bt_DBTAdapter_setPowered(JNIEnv *env, jobject obj, jbo return JNI_FALSE; } +jbyte Java_jau_direct_1bt_DBTAdapter_setPrivacyImpl(JNIEnv *env, jobject obj, jboolean enable) { + try { + shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done + JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done! + JavaGlobalObj::check(adapter_java, E_FILE_LINE); + + HCIStatusCode res = adapter->setPrivacy(JNI_TRUE == enable ? true : false); + return (jbyte) number(res); + } catch(...) { + rethrow_and_raise_java_exception(env); + } + return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE); +} + jboolean Java_jau_direct_1bt_DBTAdapter_getSecureConnectionsEnabled(JNIEnv *env, jobject obj) { try { shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done @@ -985,14 +999,14 @@ void Java_jau_direct_1bt_DBTAdapter_setSMPKeyPath(JNIEnv *env, jobject obj, jstr } } -jbyte Java_jau_direct_1bt_DBTAdapter_initializeImpl(JNIEnv *env, jobject obj, jbyte jbtMode) { +jbyte Java_jau_direct_1bt_DBTAdapter_initializeImpl(JNIEnv *env, jobject obj, jbyte jbtMode, jboolean powerOn) { try { shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done! JavaGlobalObj::check(adapter_java, E_FILE_LINE); const BTMode btMode = static_cast<BTMode>(jbtMode); - HCIStatusCode res = adapter->initialize(btMode); + HCIStatusCode res = adapter->initialize(btMode, JNI_TRUE == powerOn); return (jbyte) number(res); } catch(...) { rethrow_and_raise_java_exception(env); diff --git a/java/org/direct_bt/BTAdapter.java b/java/org/direct_bt/BTAdapter.java index ce646346..616b7960 100644 --- a/java/org/direct_bt/BTAdapter.java +++ b/java/org/direct_bt/BTAdapter.java @@ -579,6 +579,14 @@ public interface BTAdapter extends BTObject boolean setPowered(final boolean power_on); /** + * Toggle adapter privacy address mode, i.e. resolvable random address including IRK. + * @param enable toggle to enable or disable (default) + * @return HCIStatusCode::SUCCESS or an error state on failure + * @since 3.2.0 + */ + HCIStatusCode setPrivacy(boolean enable); + + /** * Returns whether Secure Connections (SC) is enabled. * @see #setSecureConnections(boolean) * @since 2.4.0 @@ -675,39 +683,16 @@ public interface BTAdapter extends BTObject * Calling the method will allow close() to power-off the adapter, * if not powered on before. * </p> - * <p> - * This override uses {@link BTMode#DUAL} - * </p> - * @return {@link HCIStatusCode#SUCCESS} or an error state on failure (e.g. power-on) - * @see #initialize(BTMode) - * @see #isInitialized() - * @see #close() - * @see #setPowered(boolean) - * @since 2.4.0 - */ - HCIStatusCode initialize(); - - /** - * Initialize the adapter with default values, including power-on. - * <p> - * Method shall be issued on the desired adapter found via {@link BTManager.ChangedAdapterSetListener}. - * </p> - * <p> - * While initialization, the adapter is first powered-off, setup and then powered-on. - * </p> - * <p> - * Calling the method will allow close() to power-off the adapter, - * if not powered on before. - * </p> * @param btMode the desired adapter's {@link BTMode}, default shall be {@link BTMode#DUAL} + * @param powerOn true to leave adapter powered-on, otherwise leave it off * * @return {@link HCIStatusCode#SUCCESS} or an error state on failure (e.g. power-on) * @see #isInitialized() * @see #initialize() * @see #close() * @see #setPowered(boolean) - * @since 2.4.0 + * @since 3.2.0 */ - HCIStatusCode initialize(final BTMode btMode); + HCIStatusCode initialize(final BTMode btMode, boolean powerOn); /** * Returns true, if {@link #initialize(BTMode)} has already been called for this adapter, otherwise false. diff --git a/src/direct_bt/BTAdapter.cpp b/src/direct_bt/BTAdapter.cpp index 3fd69ba3..948a524d 100644 --- a/src/direct_bt/BTAdapter.cpp +++ b/src/direct_bt/BTAdapter.cpp @@ -1517,11 +1517,12 @@ HCIStatusCode BTAdapter::startAdvertising(const DBGattServerRef& gattServerData_ } if constexpr ( USE_LINUX_BT_SECURITY ) { SMPIOCapability pre_io_cap { SMPIOCapability::UNSET }; - const bool res_iocap = mgmt->setIOCapability(dev_id, SMPIOCapability::NO_INPUT_NO_OUTPUT, pre_io_cap); + // SMPIOCapability new_io_cap { SMPIOCapability::DISPLAY_ONLY }; + SMPIOCapability new_io_cap { SMPIOCapability::NO_INPUT_NO_OUTPUT }; + const bool res_iocap = mgmt->setIOCapability(dev_id, new_io_cap, pre_io_cap); DBG_PRINT("BTAdapter::startAdvertising: dev_id %u, setIOCapability[%s -> %s]: result %d", - dev_id, to_string(pre_io_cap).c_str(), to_string(SMPIOCapability::NO_INPUT_NO_OUTPUT).c_str(), res_iocap); + dev_id, to_string(pre_io_cap).c_str(), to_string(new_io_cap).c_str(), res_iocap); } - // FIXME?? std::this_thread::sleep_for(std::chrono::milliseconds(100)); // wait a little (FIXME: Fast restart of advertising error) l2cap_service.start(); // set minimum ... @@ -1541,7 +1542,7 @@ HCIStatusCode BTAdapter::startAdvertising(const DBGattServerRef& gattServerData_ } const EUI48 peer_bdaddr=EUI48::ANY_DEVICE; - const HCILEOwnAddressType own_mac_type=HCILEOwnAddressType::PUBLIC; + const HCILEOwnAddressType own_mac_type=visibleMACType; const HCILEOwnAddressType peer_mac_type=HCILEOwnAddressType::PUBLIC; HCIStatusCode status = hci.le_start_adv(eir, adv_mask, scanrsp_mask, @@ -2579,7 +2580,16 @@ void BTAdapter::mgmtEvDeviceUnpairedMgmt(const MgmtEvent& e) noexcept { } void BTAdapter::mgmtEvPinCodeRequestMgmt(const MgmtEvent& e) noexcept { const MgmtEvtPinCodeRequest &event = *static_cast<const MgmtEvtPinCodeRequest *>(&e); + + BTDeviceRef device = findConnectedDevice(event.getAddress(), event.getAddressType()); + if( nullptr == device ) { + WORDY_PRINT("BTAdapter:hci:SMP: dev_id %d: Device not tracked: address[%s, %s], %s", + dev_id, event.getAddress().toString().c_str(), to_string(event.getAddressType()).c_str(), + event.toString().c_str()); + return; + } DBG_PRINT("BTAdapter:mgmt:PinCodeRequest: %s", event.toString().c_str()); + // FIXME: device->updatePairingState(device, e, HCIStatusCode::SUCCESS, SMPPairingState::PASSKEY_EXPECTED); } void BTAdapter::mgmtEvAuthFailedMgmt(const MgmtEvent& e) noexcept { const MgmtEvtAuthFailed &event = *static_cast<const MgmtEvtAuthFailed *>(&e); @@ -2605,6 +2615,7 @@ void BTAdapter::mgmtEvUserConfirmRequestMgmt(const MgmtEvent& e) noexcept { return; } // FIXME: Pass confirm_hint and value? + DBG_PRINT("BTAdapter:mgmt:UserConfirmRequest: %s", event.toString().c_str()); device->updatePairingState(device, e, HCIStatusCode::SUCCESS, SMPPairingState::NUMERIC_COMPARE_EXPECTED); } void BTAdapter::mgmtEvUserPasskeyRequestMgmt(const MgmtEvent& e) noexcept { @@ -2617,6 +2628,7 @@ void BTAdapter::mgmtEvUserPasskeyRequestMgmt(const MgmtEvent& e) noexcept { event.toString().c_str()); return; } + DBG_PRINT("BTAdapter:mgmt:UserPasskeyRequest: %s", event.toString().c_str()); device->updatePairingState(device, e, HCIStatusCode::SUCCESS, SMPPairingState::PASSKEY_EXPECTED); } diff --git a/trial/direct_bt/dbt_client01.hpp b/trial/direct_bt/dbt_client01.hpp index 67f86c24..3f3ce8f2 100644 --- a/trial/direct_bt/dbt_client01.hpp +++ b/trial/direct_bt/dbt_client01.hpp @@ -677,24 +677,24 @@ class DBTClient01 : public DBTClientTest { // Initialize with defaults and power-on if( !adapter->isInitialized() ) { - HCIStatusCode status = adapter->initialize( btMode ); + HCIStatusCode status = adapter->initialize( btMode, false ); if( HCIStatusCode::SUCCESS != status ) { fprintf_td(stderr, "initClientAdapter: Adapter initialization failed: %s: %s\n", to_string(status).c_str(), adapter->toString().c_str()); return false; } - } else if( !adapter->setPowered( true ) ) { - fprintf_td(stderr, "initClientAdapter: Already initialized adapter power-on failed:: %s\n", adapter->toString().c_str()); + } else if( !adapter->setPowered( false ) ) { + fprintf_td(stderr, "initClientAdapter: Already initialized adapter power-off failed:: %s\n", adapter->toString().c_str()); return false; } - // adapter is powered-on + // adapter is powered-off fprintf_td(stderr, "initClientAdapter.1: %s\n", adapter->toString().c_str()); { const LE_Features le_feats = adapter->getLEFeatures(); fprintf_td(stderr, "initClientAdapter: LE_Features %s\n", to_string(le_feats).c_str()); } - if( adapter->setPowered(false) ) { + { HCIStatusCode status = adapter->setName(adapterName, adapterShortName); if( HCIStatusCode::SUCCESS == status ) { fprintf_td(stderr, "initClientAdapter: setLocalName OK: %s\n", adapter->toString().c_str()); @@ -707,9 +707,6 @@ class DBTClient01 : public DBTClientTest { fprintf_td(stderr, "initClientAdapter: setPower.2 on failed: %s\n", adapter->toString().c_str()); return false; } - } else { - fprintf_td(stderr, "initClientAdapter: setPowered.2 off failed: %s\n", adapter->toString().c_str()); - return false; } // adapter is powered-on fprintf_td(stderr, "initClientAdapter.2: %s\n", adapter->toString().c_str()); diff --git a/trial/direct_bt/dbt_server01.hpp b/trial/direct_bt/dbt_server01.hpp index 450a479f..ddd0f905 100644 --- a/trial/direct_bt/dbt_server01.hpp +++ b/trial/direct_bt/dbt_server01.hpp @@ -742,20 +742,20 @@ class DBTServer01 : public DBTServerTest { if( !adapter->isInitialized() ) { // Initialize with defaults and power-on - const HCIStatusCode status = adapter->initialize( btMode ); + const HCIStatusCode status = adapter->initialize( btMode, false ); if( HCIStatusCode::SUCCESS != status ) { fprintf_td(stderr, "initServerAdapter: initialize failed: %s: %s\n", to_string(status).c_str(), adapter->toString().c_str()); return false; } - } else if( !adapter->setPowered( true ) ) { - fprintf_td(stderr, "initServerAdapter: setPower.1 on failed: %s\n", adapter->toString().c_str()); + } else if( !adapter->setPowered( false ) ) { + fprintf_td(stderr, "initServerAdapter: setPower.1 off failed: %s\n", adapter->toString().c_str()); return false; } - // adapter is powered-on + // adapter is powered-off fprintf_td(stderr, "initServerAdapter.1: %s\n", adapter->toString().c_str()); - if( adapter->setPowered(false) ) { + { HCIStatusCode status = adapter->setName(adapterName, adapterShortName); if( HCIStatusCode::SUCCESS == status ) { fprintf_td(stderr, "initServerAdapter: setLocalName OK: %s\n", adapter->toString().c_str()); @@ -790,9 +790,6 @@ class DBTServer01 : public DBTServerTest { fprintf_td(stderr, "initServerAdapter: setPower.2 on failed: %s\n", adapter->toString().c_str()); return false; } - } else { - fprintf_td(stderr, "initServerAdapter: setPowered.2 off failed: %s\n", adapter->toString().c_str()); - return false; } // adapter is powered-on fprintf_td(stderr, "initServerAdapter.2: %s\n", adapter->toString().c_str()); diff --git a/trial/java/trial/org/direct_bt/DBTClient01.java b/trial/java/trial/org/direct_bt/DBTClient01.java index a37df5c7..ecc5feb3 100644 --- a/trial/java/trial/org/direct_bt/DBTClient01.java +++ b/trial/java/trial/org/direct_bt/DBTClient01.java @@ -679,20 +679,20 @@ public class DBTClient01 implements DBTClientTest { // Initialize with defaults and power-on if( !adapter.isInitialized() ) { - final HCIStatusCode status = adapter.initialize( btMode ); + final HCIStatusCode status = adapter.initialize( btMode, false ); if( HCIStatusCode.SUCCESS != status ) { PrintUtil.fprintf_td(System.err, "initClientAdapter: Adapter initialization failed: %s: %s\n", status.toString(), adapter.toString()); return false; } - } else if( !adapter.setPowered( true ) ) { - PrintUtil.fprintf_td(System.err, "initClientAdapter: Already initialized adapter power-on failed:: %s\n", adapter.toString()); + } else if( !adapter.setPowered( false ) ) { + PrintUtil.fprintf_td(System.err, "initClientAdapter: Already initialized adapter power-off failed:: %s\n", adapter.toString()); return false; } - // adapter is powered-on + // adapter is powered-off PrintUtil.fprintf_td(System.err, "initClientAdapter.1: %s\n", adapter.toString()); - if( adapter.setPowered(false) ) { + { final HCIStatusCode status = adapter.setName(adapterName, adapterShortName); if( HCIStatusCode.SUCCESS == status ) { PrintUtil.fprintf_td(System.err, "initClientAdapter: setLocalName OK: %s\n", adapter.toString()); @@ -704,8 +704,6 @@ public class DBTClient01 implements DBTClientTest { PrintUtil.fprintf_td(System.err, "initClientAdapter: setPower.2 on failed: %s\n", adapter.toString()); return false; } - } else { - PrintUtil.fprintf_td(System.err, "initClientAdapter: setPowered.2 off failed: %s\n", adapter.toString()); } // adapter is powered-on PrintUtil.println(System.err, "initClientAdapter.2: "+adapter.toString()); diff --git a/trial/java/trial/org/direct_bt/DBTServer01.java b/trial/java/trial/org/direct_bt/DBTServer01.java index 9842422a..c9c28a48 100644 --- a/trial/java/trial/org/direct_bt/DBTServer01.java +++ b/trial/java/trial/org/direct_bt/DBTServer01.java @@ -766,20 +766,20 @@ public class DBTServer01 implements DBTServerTest { if( !adapter.isInitialized() ) { // Initialize with defaults and power-on - final HCIStatusCode status = adapter.initialize( btMode ); + final HCIStatusCode status = adapter.initialize( btMode, false ); if( HCIStatusCode.SUCCESS != status ) { PrintUtil.fprintf_td(System.err, "initServerAdapter: initialization failed: %s: %s\n", status.toString(), adapter.toString()); return false; } - } else if( !adapter.setPowered( true ) ) { - PrintUtil.fprintf_td(System.err, "initServerAdapter: setPower.1 on failed: %s\n", adapter.toString()); + } else if( !adapter.setPowered( false ) ) { + PrintUtil.fprintf_td(System.err, "initServerAdapter: setPower.1 off failed: %s\n", adapter.toString()); return false; } - // adapter is powered-on + // adapter is powered-off PrintUtil.println(System.err, "initServerAdapter.1: "+adapter.toString()); - if( adapter.setPowered(false) ) { + { HCIStatusCode status = adapter.setName(adapterName, adapterShortName); if( HCIStatusCode.SUCCESS == status ) { PrintUtil.fprintf_td(System.err, "initServerAdapter: setLocalName OK: %s\n", adapter.toString()); @@ -814,8 +814,6 @@ public class DBTServer01 implements DBTServerTest { PrintUtil.fprintf_td(System.err, "initServerAdapter: setPower.2 on failed: %s\n", adapter.toString()); return false; } - } else { - PrintUtil.fprintf_td(System.err, "initServerAdapter: setPowered.2 off failed: %s\n", adapter.toString()); } // adapter is powered-on PrintUtil.println(System.err, "initServerAdapter.2: "+adapter.toString()); |