diff options
-rw-r--r-- | system/BUILD.gn | 1 | ||||
-rw-r--r-- | system/bta/Android.bp | 1 | ||||
-rw-r--r-- | system/common/Android.bp | 3 | ||||
-rw-r--r-- | system/gd/hci/address.h | 118 | ||||
-rw-r--r-- | system/gd/hci/class_of_device.h | 83 | ||||
-rw-r--r-- | system/gd/hci/distance_measurement_manager.h | 2 | ||||
-rw-r--r-- | system/osi/Android.bp | 1 | ||||
-rw-r--r-- | system/pdl/BUILD.gn | 5 | ||||
-rw-r--r-- | system/pdl/hci/include/hci/class_of_device.h | 2 | ||||
-rw-r--r-- | system/stack/mmc/BUILD.gn | 1 |
10 files changed, 12 insertions, 205 deletions
diff --git a/system/BUILD.gn b/system/BUILD.gn index 01286ec4e8..b86ca5f392 100644 --- a/system/BUILD.gn +++ b/system/BUILD.gn @@ -79,6 +79,7 @@ config("target_defaults") { "//bt/system/linux_include", "//bt/system/include", "//bt/system/gd", + "//bt/system/pdl/hci/include", # For flatbuffer generated headers "${root_gen_dir}/bt/system/gd/", diff --git a/system/bta/Android.bp b/system/bta/Android.bp index bfdea63d54..52d34d59cc 100644 --- a/system/bta/Android.bp +++ b/system/bta/Android.bp @@ -461,6 +461,7 @@ cc_test { static_libs: [ "bluetooth_flags_c_lib", "libbluetooth-types", + "libbluetooth_hci_pdl", "libbluetooth_log", "libbt-common", "libbt-platform-protos-lite", diff --git a/system/common/Android.bp b/system/common/Android.bp index 6fe25539d9..e4efd7156e 100644 --- a/system/common/Android.bp +++ b/system/common/Android.bp @@ -54,6 +54,7 @@ cc_library_static { header_libs: ["libbluetooth_headers"], static_libs: [ "libbluetooth_crypto_toolbox", + "libbluetooth_hci_pdl", "libbluetooth_log", "libbt-platform-protos-lite", ], @@ -101,7 +102,7 @@ cc_test { static_libs: [ "libbluetooth-types", "libbluetooth_crypto_toolbox", - "libbluetooth_log", + "libbluetooth_hci_pdl", "libbluetooth_log", "libbt-common", "libbt-platform-protos-lite", diff --git a/system/gd/hci/address.h b/system/gd/hci/address.h deleted file mode 100644 index 17c2fce6b4..0000000000 --- a/system/gd/hci/address.h +++ /dev/null @@ -1,118 +0,0 @@ -/****************************************************************************** - * - * Copyright 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -#pragma once - -#include <array> -#include <cstring> -#include <initializer_list> -#include <optional> -#include <ostream> -#include <string> - -#include "packet/custom_field_fixed_size_interface.h" -#include "storage/serializable.h" - -namespace bluetooth { -namespace hci { - -class Address final : public packet::CustomFieldFixedSizeInterface<Address>, - public storage::Serializable<Address> { -public: - static constexpr size_t kLength = 6; - - // Bluetooth MAC address bytes saved in little endian format. - // The address MSB is address[5], the address LSB is address[0]. - // Note that the textual representation follows the big endian format, - // ie. Address{0, 1, 2, 3, 4, 5} is represented as 05:04:03:02:01:00. - std::array<uint8_t, kLength> address = {}; - - Address() = default; - Address(const uint8_t (&addr)[kLength]); - Address(std::initializer_list<uint8_t> l); - - // CustomFieldFixedSizeInterface methods - inline uint8_t* data() override { return address.data(); } - inline const uint8_t* data() const override { return address.data(); } - - // storage::Serializable methods - std::string ToString() const override; - std::string ToColonSepHexString() const; - std::string ToStringForLogging() const; - std::string ToRedactedStringForLogging() const; - - static std::optional<Address> FromString(const std::string& from); - std::string ToLegacyConfigString() const override; - static std::optional<Address> FromLegacyConfigString(const std::string& str); - - bool operator<(const Address& rhs) const { return address < rhs.address; } - bool operator==(const Address& rhs) const { return address == rhs.address; } - bool operator>(const Address& rhs) const { return rhs < *this; } - bool operator<=(const Address& rhs) const { return !(*this > rhs); } - bool operator>=(const Address& rhs) const { return !(*this < rhs); } - bool operator!=(const Address& rhs) const { return !(*this == rhs); } - - bool IsEmpty() const { return *this == kEmpty; } - - // Converts |string| to Address and places it in |to|. If |from| does - // not represent a Bluetooth address, |to| is not modified and this function - // returns false. Otherwise, it returns true. - static bool FromString(const std::string& from, Address& to); - - // Copies |from| raw Bluetooth address octets to the local object. - // Returns the number of copied octets - should be always Address::kLength - size_t FromOctets(const uint8_t* from); - - static bool IsValidAddress(const std::string& address); - - static const Address kEmpty; // 00:00:00:00:00:00 - static const Address kAny; // FF:FF:FF:FF:FF:FF -private: - std::string _ToMaskedColonSepHexString(int bytes_to_mask) const; -}; - -} // namespace hci -} // namespace bluetooth - -namespace std { -template <> -struct hash<bluetooth::hci::Address> { - std::size_t operator()(const bluetooth::hci::Address& val) const { - static_assert(sizeof(uint64_t) >= bluetooth::hci::Address::kLength); - uint64_t int_addr = 0; - memcpy(reinterpret_cast<uint8_t*>(&int_addr), val.data(), bluetooth::hci::Address::kLength); - return std::hash<uint64_t>{}(int_addr); - } -}; -} // namespace std - -#if __has_include(<bluetooth/log.h>) -#include <bluetooth/log.h> - -namespace std { -template <> -struct formatter<bluetooth::hci::Address> : formatter<std::string> { - template <class Context> - typename Context::iterator format(const bluetooth::hci::Address& address, Context& ctx) const { - std::string repr = address.ToRedactedStringForLogging(); - return std::formatter<std::string>::format(repr, ctx); - } -}; -} // namespace std - -#endif // __has_include(<bluetooth/log.h> diff --git a/system/gd/hci/class_of_device.h b/system/gd/hci/class_of_device.h deleted file mode 100644 index d4d53eb1d7..0000000000 --- a/system/gd/hci/class_of_device.h +++ /dev/null @@ -1,83 +0,0 @@ -/****************************************************************************** - * - * Copyright 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -#pragma once - -#include <array> -#include <optional> -#include <string> - -#include "packet/custom_field_fixed_size_interface.h" -#include "storage/serializable.h" - -namespace bluetooth { -namespace hci { - -class ClassOfDevice final : public packet::CustomFieldFixedSizeInterface<ClassOfDevice>, - public storage::Serializable<ClassOfDevice> { -public: - static constexpr size_t kLength = 3; - - std::array<uint8_t, kLength> cod = {}; - - ClassOfDevice() = default; - ClassOfDevice(const uint8_t (&class_of_device)[kLength]); - - // packet::CustomFieldFixedSizeInterface methods - inline uint8_t* data() override { return cod.data(); } - inline const uint8_t* data() const override { return cod.data(); } - - // storage::Serializable methods - std::string ToString() const override; - static std::optional<ClassOfDevice> FromString(const std::string& str); - std::string ToLegacyConfigString() const override; - static std::optional<ClassOfDevice> FromLegacyConfigString(const std::string& str); - - bool operator<(const ClassOfDevice& rhs) const { return cod < rhs.cod; } - bool operator==(const ClassOfDevice& rhs) const { return cod == rhs.cod; } - bool operator>(const ClassOfDevice& rhs) const { return rhs < *this; } - bool operator<=(const ClassOfDevice& rhs) const { return !(*this > rhs); } - bool operator>=(const ClassOfDevice& rhs) const { return !(*this < rhs); } - bool operator!=(const ClassOfDevice& rhs) const { return !(*this == rhs); } - - // Converts |string| to ClassOfDevice and places it in |to|. If |from| does - // not represent a Class of Device, |to| is not modified and this function - // returns false. Otherwise, it returns true. - static bool FromString(const std::string& from, ClassOfDevice& to); - - // Converts uint32_t encoded class of device to ClassOfDevice object - // uint32_t encoding: - // <high> uint8_t(cod[0]) | uint8_t(cod[1]) | uint8_t(cod[2]) <low> - // Only used in legacy stack device config - static std::optional<ClassOfDevice> FromUint32Legacy(uint32_t cod_int); - uint32_t ToUint32Legacy() const; - - // Copies |from| raw Class of Device octets to the local object. - // Returns the number of copied octets (always ClassOfDevice::kLength) - size_t FromOctets(const uint8_t* from); - - static bool IsValid(const std::string& class_of_device); -}; - -inline std::ostream& operator<<(std::ostream& os, const ClassOfDevice& c) { - os << c.ToString(); - return os; -} - -} // namespace hci -} // namespace bluetooth diff --git a/system/gd/hci/distance_measurement_manager.h b/system/gd/hci/distance_measurement_manager.h index d8c3d49aea..c0f3cae654 100644 --- a/system/gd/hci/distance_measurement_manager.h +++ b/system/gd/hci/distance_measurement_manager.h @@ -17,9 +17,9 @@ #include <bluetooth/log.h> -#include "address.h" #include "bta/include/bta_ras_api.h" #include "hal/ranging_hal.h" +#include "hci/address.h" #include "hci/hci_packets.h" #include "module.h" diff --git a/system/osi/Android.bp b/system/osi/Android.bp index 9d26c957ec..0c008ff771 100644 --- a/system/osi/Android.bp +++ b/system/osi/Android.bp @@ -86,6 +86,7 @@ cc_library_static { static_libs: [ "bluetooth_flags_c_lib", "libaconfig_storage_read_api_cc", + "libbluetooth_hci_pdl", "libbluetooth_log", "libbt-platform-protos-lite", "libcom.android.sysprop.bluetooth.wrapped", diff --git a/system/pdl/BUILD.gn b/system/pdl/BUILD.gn index c79976fdd7..6ef124e879 100644 --- a/system/pdl/BUILD.gn +++ b/system/pdl/BUILD.gn @@ -21,7 +21,10 @@ source_set("BluetoothHciPacketSources") { "hci/class_of_device.cc", ] - include_dirs = [ "//bt/system/gd" ] + include_dirs = [ + "hci/include", + "//bt/system/gd", + ] } packetgen_headers("BluetoothGeneratedPackets_h") { diff --git a/system/pdl/hci/include/hci/class_of_device.h b/system/pdl/hci/include/hci/class_of_device.h index d3a57fcc33..d4d53eb1d7 100644 --- a/system/pdl/hci/include/hci/class_of_device.h +++ b/system/pdl/hci/include/hci/class_of_device.h @@ -43,7 +43,7 @@ public: inline const uint8_t* data() const override { return cod.data(); } // storage::Serializable methods - std::string ToString() const; + std::string ToString() const override; static std::optional<ClassOfDevice> FromString(const std::string& str); std::string ToLegacyConfigString() const override; static std::optional<ClassOfDevice> FromLegacyConfigString(const std::string& str); diff --git a/system/stack/mmc/BUILD.gn b/system/stack/mmc/BUILD.gn index e4df3a7f07..dd5d1308c6 100644 --- a/system/stack/mmc/BUILD.gn +++ b/system/stack/mmc/BUILD.gn @@ -40,6 +40,7 @@ pkg_config("target_defaults") { "//bt/system", "//bt/system/gd", "//bt/system/include", + "//bt/system/pdl/hci/include", "//bt/system/stack", "//bt/system/stack/include", ] |