From: Chris Manton Date: Thu, 29 Oct 2020 05:40:43 +0000 (-0700) Subject: Add types/ble_address_with_type.h X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=bab320bd3ff964bfa093106a0d389c3f758a7a37;p=android-x86%2Fsystem-bt.git Add types/ble_address_with_type.h Toward readable code Bug: 163134718 Tag: #refactor Test: compile & verify basic functions working Change-Id: I9028ab92ed646b414f206571ebb031573ab87b82 --- diff --git a/bta/include/bta_api.h b/bta/include/bta_api.h index 172657f9c..c4b50acb1 100644 --- a/bta/include/bta_api.h +++ b/bta/include/bta_api.h @@ -31,6 +31,7 @@ #include "bt_types.h" #include "btm_api.h" #include "btm_ble_api.h" +#include "types/ble_address_with_type.h" #include "types/bt_transport.h" /***************************************************************************** diff --git a/btif/include/btif_config.h b/btif/include/btif_config.h index 8729ad150..57a4f1e33 100644 --- a/btif/include/btif_config.h +++ b/btif/include/btif_config.h @@ -26,6 +26,7 @@ #include #include #include "osi/include/config.h" +#include "types/ble_address_with_type.h" static const char BTIF_CONFIG_MODULE[] = "btif_config_module"; diff --git a/btif/include/btif_storage.h b/btif/include/btif_storage.h index 847361233..b2880a6af 100644 --- a/btif/include/btif_storage.h +++ b/btif/include/btif_storage.h @@ -24,6 +24,7 @@ #include "bt_target.h" #include "bt_types.h" +#include "types/ble_address_with_type.h" /******************************************************************************* * Constants & Macros diff --git a/main/shim/acl_api.cc b/main/shim/acl_api.cc index b305f869a..ba4190931 100644 --- a/main/shim/acl_api.cc +++ b/main/shim/acl_api.cc @@ -20,6 +20,7 @@ #include "main/shim/acl_api.h" #include "main/shim/helpers.h" #include "main/shim/stack.h" +#include "types/ble_address_with_type.h" #include "types/raw_address.h" void bluetooth::shim::ACL_CreateClassicConnection( diff --git a/main/shim/acl_api.h b/main/shim/acl_api.h index 53aaf49e5..07e513fc2 100644 --- a/main/shim/acl_api.h +++ b/main/shim/acl_api.h @@ -17,6 +17,7 @@ #pragma once #include "stack/include/bt_types.h" +#include "types/ble_address_with_type.h" #include "types/raw_address.h" namespace bluetooth { diff --git a/main/shim/acl_legacy_interface.h b/main/shim/acl_legacy_interface.h index ebf578321..ea95c25bc 100644 --- a/main/shim/acl_legacy_interface.h +++ b/main/shim/acl_legacy_interface.h @@ -19,6 +19,7 @@ #include #include "stack/include/bt_types.h" #include "stack/include/hci_error_code.h" +#include "types/ble_address_with_type.h" #include "types/raw_address.h" namespace bluetooth { diff --git a/main/shim/helpers.h b/main/shim/helpers.h index 37ac502ce..397559761 100644 --- a/main/shim/helpers.h +++ b/main/shim/helpers.h @@ -21,6 +21,7 @@ #include "osi/include/allocator.h" #include "stack/include/bt_types.h" #include "stack/include/hci_error_code.h" +#include "types/ble_address_with_type.h" namespace bluetooth { diff --git a/stack/btm/neighbor_inquiry.h b/stack/btm/neighbor_inquiry.h index 495483864..7580a0ec5 100644 --- a/stack/btm/neighbor_inquiry.h +++ b/stack/btm/neighbor_inquiry.h @@ -20,6 +20,7 @@ #include "osi/include/alarm.h" #include "stack/include/btm_api_types.h" +#include "types/ble_address_with_type.h" #include "types/raw_address.h" /* Discoverable modes */ diff --git a/stack/include/bt_types.h b/stack/include/bt_types.h index 4380ed670..e11a7a6d8 100644 --- a/stack/include/bt_types.h +++ b/stack/include/bt_types.h @@ -676,83 +676,6 @@ typedef struct { #define BRCM_RESERVED_PSM_START 0x5AE1 #define BRCM_RESERVED_PSM_END 0x5AFF -/***************************************************************************** - * Low Energy definitions - * - * Address types - */ -#define BLE_ADDR_PUBLIC 0x00 -#define BLE_ADDR_RANDOM 0x01 -#define BLE_ADDR_PUBLIC_ID 0x02 -#define BLE_ADDR_RANDOM_ID 0x03 -#define BLE_ADDR_ANONYMOUS 0xFF -typedef uint8_t tBLE_ADDR_TYPE; -#ifdef __cplusplus -inline std::string AddressTypeText(tBLE_ADDR_TYPE type) { - switch (type) { - case BLE_ADDR_PUBLIC: - return std::string("public"); - case BLE_ADDR_RANDOM: - return std::string("random"); - case BLE_ADDR_PUBLIC_ID: - return std::string("public identity"); - case BLE_ADDR_RANDOM_ID: - return std::string("random identity"); - case BLE_ADDR_ANONYMOUS: - return std::string("anonymous"); - default: - return std::string("unknown"); - } -} -#endif // __cplusplus - -/* BLE ADDR type ID bit */ -#define BLE_ADDR_TYPE_ID_BIT 0x02 - -#ifdef __cplusplus -constexpr uint8_t kBleAddressPublicDevice = BLE_ADDR_PUBLIC; -constexpr uint8_t kBleAddressRandomDevice = BLE_ADDR_RANDOM; -constexpr uint8_t kBleAddressIdentityBit = BLE_ADDR_TYPE_ID_BIT; -constexpr uint8_t kBleAddressPublicIdentity = - kBleAddressIdentityBit | kBleAddressPublicDevice; -constexpr uint8_t kBleAddressRandomIdentity = - kBleAddressIdentityBit | kBleAddressRandomDevice; - -constexpr uint8_t kResolvableAddressMask = 0xc0; -constexpr uint8_t kResolvableAddressMsb = 0x40; - -struct tBLE_BD_ADDR { - tBLE_ADDR_TYPE type; - RawAddress bda; - bool AddressEquals(const RawAddress& other) const { return other == bda; } - bool IsPublicDeviceType() const { return type == kBleAddressPublicDevice; } - bool IsRandomDeviceType() const { return type == kBleAddressRandomDevice; } - bool IsPublicIdentityType() const { - return type == kBleAddressPublicIdentity; - } - bool lsRandomIdentityType() const { - return type == kBleAddressRandomIdentity; - } - bool IsAddressResolvable() const { - return ((bda.address)[0] & kResolvableAddressMask) == kResolvableAddressMsb; - } - bool IsPublic() const { return type & 0x01; } - bool IsResolvablePrivateAddress() const { - return IsAddressResolvable() && IsRandomDeviceType(); - } - bool IsIdentityType() const { - return IsPublicIdentityType() || lsRandomIdentityType(); - } - bool TypeWithoutIdentityEquals(const tBLE_ADDR_TYPE other) const { - return (other & ~kBleAddressIdentityBit) == - (type & ~kBleAddressIdentityBit); - } - std::string ToString() const { - return std::string(bda.ToString() + "[" + AddressTypeText(type) + "]"); - } -}; -#endif - /* Device Types */ enum : uint8_t { diff --git a/stack/include/btm_api_types.h b/stack/include/btm_api_types.h index 57662aeab..f5b34679f 100644 --- a/stack/include/btm_api_types.h +++ b/stack/include/btm_api_types.h @@ -26,6 +26,7 @@ #include "stack/include/btm_status.h" #include "stack/include/hcidefs.h" #include "stack/include/smp_api_types.h" +#include "types/ble_address_with_type.h" #include "types/bt_transport.h" /* Device name of peer (may be truncated to save space in BTM database) */ diff --git a/stack/include/btm_ble_api_types.h b/stack/include/btm_ble_api_types.h index 08f0580b6..f98f2ab80 100644 --- a/stack/include/btm_ble_api_types.h +++ b/stack/include/btm_ble_api_types.h @@ -22,6 +22,7 @@ #include #include #include +#include "types/ble_address_with_type.h" #define CHNL_MAP_LEN 5 typedef uint8_t tBTM_BLE_CHNL_MAP[CHNL_MAP_LEN]; diff --git a/stack/include/smp_api_types.h b/stack/include/smp_api_types.h index 335a6d854..98e7a9226 100644 --- a/stack/include/smp_api_types.h +++ b/stack/include/smp_api_types.h @@ -20,6 +20,7 @@ #define SMP_API_TYPES_H #include "bt_target.h" +#include "types/ble_address_with_type.h" /* SMP command code */ #define SMP_OPCODE_PAIRING_REQ 0x01 diff --git a/types/ble_address_with_type.h b/types/ble_address_with_type.h new file mode 100644 index 000000000..850abb900 --- /dev/null +++ b/types/ble_address_with_type.h @@ -0,0 +1,93 @@ +/* + * Copyright 2020 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 +#include +#include "types/raw_address.h" + +#define BLE_ADDR_PUBLIC 0x00 +#define BLE_ADDR_RANDOM 0x01 +#define BLE_ADDR_PUBLIC_ID 0x02 +#define BLE_ADDR_RANDOM_ID 0x03 +#define BLE_ADDR_ANONYMOUS 0xFF +typedef uint8_t tBLE_ADDR_TYPE; +#ifdef __cplusplus +inline std::string AddressTypeText(tBLE_ADDR_TYPE type) { + switch (type) { + case BLE_ADDR_PUBLIC: + return std::string("public"); + case BLE_ADDR_RANDOM: + return std::string("random"); + case BLE_ADDR_PUBLIC_ID: + return std::string("public identity"); + case BLE_ADDR_RANDOM_ID: + return std::string("random identity"); + case BLE_ADDR_ANONYMOUS: + return std::string("anonymous"); + default: + return std::string("unknown"); + } +} +#endif // __cplusplus + +/* BLE ADDR type ID bit */ +#define BLE_ADDR_TYPE_ID_BIT 0x02 + +#ifdef __cplusplus +constexpr uint8_t kBleAddressPublicDevice = BLE_ADDR_PUBLIC; +constexpr uint8_t kBleAddressRandomDevice = BLE_ADDR_RANDOM; +constexpr uint8_t kBleAddressIdentityBit = BLE_ADDR_TYPE_ID_BIT; +constexpr uint8_t kBleAddressPublicIdentity = + kBleAddressIdentityBit | kBleAddressPublicDevice; +constexpr uint8_t kBleAddressRandomIdentity = + kBleAddressIdentityBit | kBleAddressRandomDevice; + +constexpr uint8_t kResolvableAddressMask = 0xc0; +constexpr uint8_t kResolvableAddressMsb = 0x40; + +struct tBLE_BD_ADDR { + tBLE_ADDR_TYPE type; + RawAddress bda; + bool AddressEquals(const RawAddress& other) const { return other == bda; } + bool IsPublicDeviceType() const { return type == kBleAddressPublicDevice; } + bool IsRandomDeviceType() const { return type == kBleAddressRandomDevice; } + bool IsPublicIdentityType() const { + return type == kBleAddressPublicIdentity; + } + bool lsRandomIdentityType() const { + return type == kBleAddressRandomIdentity; + } + bool IsAddressResolvable() const { + return ((bda.address)[0] & kResolvableAddressMask) == kResolvableAddressMsb; + } + bool IsPublic() const { return type & 0x01; } + bool IsResolvablePrivateAddress() const { + return IsAddressResolvable() && IsRandomDeviceType(); + } + bool IsIdentityType() const { + return IsPublicIdentityType() || lsRandomIdentityType(); + } + bool TypeWithoutIdentityEquals(const tBLE_ADDR_TYPE other) const { + return (other & ~kBleAddressIdentityBit) == + (type & ~kBleAddressIdentityBit); + } + std::string ToString() const { + return std::string(bda.ToString() + "[" + AddressTypeText(type) + "]"); + } +}; +#endif