diff options
author | Sven Gothel <[email protected]> | 2021-07-28 10:50:12 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-07-28 10:50:12 +0200 |
commit | c7b62da9a528de1e032c5189178af0ab60fff5b1 (patch) | |
tree | e44ed239eafb4b8db8bd23f1281879d77a960679 /api | |
parent | d02d3d11d4a67b0951e671ff4273bda02594906f (diff) |
Add BTAdapter::[getV|v]isibleAddressAndType[()] and BTAdapter::get[Address->AddressAndType]() using BDAddressAndType, preparing for random address
Thoroughly changes
- 'EUI48 AdapterInfo::address' -> 'BDAddressAndType AdapterInfo::addressAndType'
- BTAdapter C++
- BTAdapter and its DBTAdapter/DBusAdapter implementations (Java)
Motivation:
- The adapter's address as initially reported by the system is always its public address, i.e. BDAddressType::BDADDR_LE_PUBLIC
- The adapter's visible BDAddressAndType might be set to BDAddressType::BDADDR_LE_RANDOM before scanning / discovery mode (TODO).
Diffstat (limited to 'api')
-rw-r--r-- | api/direct_bt/BTAdapter.hpp | 28 | ||||
-rw-r--r-- | api/direct_bt/BTManager.hpp | 5 | ||||
-rw-r--r-- | api/direct_bt/BTTypes1.hpp | 21 | ||||
-rw-r--r-- | api/direct_bt/L2CAPComm.hpp | 6 | ||||
-rw-r--r-- | api/direct_bt/MgmtTypes.hpp | 1 |
5 files changed, 45 insertions, 16 deletions
diff --git a/api/direct_bt/BTAdapter.hpp b/api/direct_bt/BTAdapter.hpp index bad301d0..76c48b36 100644 --- a/api/direct_bt/BTAdapter.hpp +++ b/api/direct_bt/BTAdapter.hpp @@ -255,6 +255,11 @@ namespace direct_bt { BTManager& mgmt; AdapterInfo adapterInfo; + /** + * Either the adapter's initially reported public address or a random address setup via HCI before scanning / discovery. + */ + BDAddressAndType visibleAddressAndType; + public: /** * Adapter's internal temporary device id. @@ -463,7 +468,28 @@ namespace direct_bt { */ BTMode getBTMode() const noexcept { return adapterInfo.getCurrentBTMode(); } - EUI48 const & getAddress() const noexcept { return adapterInfo.address; } + /** + * Returns the adapter's public BDAddressAndType. + * <p> + * The adapter's address as initially reported by the system is always its public address, i.e. BDAddressType::BDADDR_LE_PUBLIC. + * </p> + * @since 2.2.8 + * @see #getVisibleAddressAndType() + */ + BDAddressAndType const & getAddressAndType() const noexcept { return adapterInfo.addressAndType; } + + /** + * Returns the adapter's currently visible BDAddressAndType. + * <p> + * The adapter's address as initially reported by the system is always its public address, i.e. BDAddressType::BDADDR_LE_PUBLIC. + * </p> + * <p> + * The adapter's visible BDAddressAndType might be set to BDAddressType::BDADDR_LE_RANDOM before scanning / discovery mode (TODO). + * </p> + * @since 2.2.8 + * @see #getAddressAndType() + */ + BDAddressAndType const & getVisibleAddressAndType() const noexcept { return visibleAddressAndType; } /** * Returns the system name. diff --git a/api/direct_bt/BTManager.hpp b/api/direct_bt/BTManager.hpp index 428422c6..5cfd16e9 100644 --- a/api/direct_bt/BTManager.hpp +++ b/api/direct_bt/BTManager.hpp @@ -367,11 +367,6 @@ namespace direct_bt { jau::darray<std::shared_ptr<BTAdapter>> getAdapters() { return *adapters.snapshot(); } /** - * Returns the DBTAdapter with the given address or nullptr if not found. - */ - std::shared_ptr<BTAdapter> getAdapter(const EUI48 &mac) const noexcept; - - /** * Returns the DBTAdapter with the given dev_id, or nullptr if not found. */ std::shared_ptr<BTAdapter> getAdapter(const uint16_t dev_id) const noexcept; diff --git a/api/direct_bt/BTTypes1.hpp b/api/direct_bt/BTTypes1.hpp index 9379b403..94da366a 100644 --- a/api/direct_bt/BTTypes1.hpp +++ b/api/direct_bt/BTTypes1.hpp @@ -186,7 +186,14 @@ namespace direct_bt { public: const uint16_t dev_id; - const EUI48 address; + /** + * The adapter's address initially reported by the system is always its public address, i.e. BDAddressType::BDADDR_LE_PUBLIC. + * <p> + * Subsequent adapter setup using BDAddressType::BDADDR_LE_RANDOM must be handled within BTAdapter + * and is not reflected in AdapterInfo. + * </p> + */ + const BDAddressAndType addressAndType; const uint8_t version; const uint16_t manufacturer; @@ -212,11 +219,11 @@ namespace direct_bt { void setShortName(const std::string v) noexcept { short_name = v; } public: - AdapterInfo(const uint16_t dev_id_, const EUI48 & address_, + AdapterInfo(const uint16_t dev_id_, const BDAddressAndType & addressAndType_, const uint8_t version_, const uint16_t manufacturer_, const AdapterSetting supported_setting_, const AdapterSetting current_setting_, const uint32_t dev_class_, const std::string & name_, const std::string & short_name_) noexcept - : dev_id(dev_id_), address(address_), version(version_), + : dev_id(dev_id_), addressAndType(addressAndType_), version(version_), manufacturer(manufacturer_), supported_setting(supported_setting_), current_setting(current_setting_), dev_class(dev_class_), @@ -224,7 +231,7 @@ namespace direct_bt { { } AdapterInfo(const AdapterInfo &o) noexcept - : dev_id(o.dev_id), address(o.address), version(o.version), + : dev_id(o.dev_id), addressAndType(o.addressAndType), version(o.version), manufacturer(o.manufacturer), supported_setting(o.supported_setting), current_setting(o.current_setting.load()), dev_class(o.dev_class), @@ -232,7 +239,7 @@ namespace direct_bt { { } AdapterInfo& operator=(const AdapterInfo &o) { if( this != &o ) { - if( dev_id != o.dev_id || address != o.address ) { + if( dev_id != o.dev_id || addressAndType != o.addressAndType ) { throw jau::IllegalArgumentException("Can't assign different device id's or address "+o.toString()+" -> "+toString(), E_FILE_LINE); } supported_setting = o.supported_setting; @@ -244,7 +251,7 @@ namespace direct_bt { return *this; } AdapterInfo(AdapterInfo&& o) noexcept - : dev_id(std::move(o.dev_id)), address(std::move(o.address)), version(std::move(o.version)), + : dev_id(std::move(o.dev_id)), addressAndType(std::move(o.addressAndType)), version(std::move(o.version)), manufacturer(std::move(o.manufacturer)), supported_setting(std::move(o.supported_setting)), current_setting(o.current_setting.load()), dev_class(std::move(o.dev_class)), @@ -268,7 +275,7 @@ namespace direct_bt { std::string getShortName() const noexcept { return short_name; } std::string toString() const noexcept { - return "AdapterInfo[id "+std::to_string(dev_id)+", address "+address.toString()+", version "+std::to_string(version)+ + return "AdapterInfo[id "+std::to_string(dev_id)+", address "+addressAndType.toString()+", version "+std::to_string(version)+ ", manuf "+std::to_string(manufacturer)+ ", settings[sup "+to_string(supported_setting)+", cur "+to_string(current_setting)+ "], name '"+name+"', shortName '"+short_name+"']"; diff --git a/api/direct_bt/L2CAPComm.hpp b/api/direct_bt/L2CAPComm.hpp index e9922531..40e9a85e 100644 --- a/api/direct_bt/L2CAPComm.hpp +++ b/api/direct_bt/L2CAPComm.hpp @@ -122,11 +122,11 @@ namespace direct_bt { } private: - static int l2cap_open_dev(const EUI48 & adapterAddress, const L2CAP_PSM psm, const L2CAP_CID cid, const BDAddressType addrType); + static int l2cap_open_dev(const BDAddressAndType & adapterAddressAndType, const L2CAP_PSM psm, const L2CAP_CID cid); static int l2cap_close_dev(int dd); const L2CAPEnv & env; - const EUI48 adapterAddress; + const BDAddressAndType adapterAddressAndType; const L2CAP_PSM psm; const L2CAP_CID cid; @@ -146,7 +146,7 @@ namespace direct_bt { /** * Constructing a non connected L2CAP channel instance for the pre-defined PSM and CID. */ - L2CAPComm(const EUI48& adapterAddress, const L2CAP_PSM psm, const L2CAP_CID cid); + L2CAPComm(const BDAddressAndType& adapterAddressAndType, const L2CAP_PSM psm, const L2CAP_CID cid); L2CAPComm(const L2CAPComm&) = delete; void operator=(const L2CAPComm&) = delete; diff --git a/api/direct_bt/MgmtTypes.hpp b/api/direct_bt/MgmtTypes.hpp index 90382539..0dd79ff6 100644 --- a/api/direct_bt/MgmtTypes.hpp +++ b/api/direct_bt/MgmtTypes.hpp @@ -2213,6 +2213,7 @@ namespace direct_bt { : MgmtEvtCmdComplete(buffer, buffer_len, infoDataSize()) { } + /** The adapter address reported is always the public address, i.e. BDAddressType::BDADDR_LE_PUBLIC. */ const EUI48& getAddress() const noexcept { return *reinterpret_cast<const EUI48 *>( pdu.get_ptr_nc(getDataOffset() + 0) ); } uint8_t getVersion() const noexcept { return pdu.get_uint8_nc(getDataOffset()+6); } uint16_t getManufacturer() const noexcept { return pdu.get_uint16_nc(getDataOffset()+7); } |