OSDN Git Service

Add types/ble_address_with_type.h
authorChris Manton <cmanton@google.com>
Thu, 29 Oct 2020 05:40:43 +0000 (22:40 -0700)
committerChris Manton <cmanton@google.com>
Thu, 29 Oct 2020 17:21:44 +0000 (10:21 -0700)
Toward readable code

Bug: 163134718
Tag: #refactor
Test: compile & verify basic functions working

Change-Id: I9028ab92ed646b414f206571ebb031573ab87b82

13 files changed:
bta/include/bta_api.h
btif/include/btif_config.h
btif/include/btif_storage.h
main/shim/acl_api.cc
main/shim/acl_api.h
main/shim/acl_legacy_interface.h
main/shim/helpers.h
stack/btm/neighbor_inquiry.h
stack/include/bt_types.h
stack/include/btm_api_types.h
stack/include/btm_ble_api_types.h
stack/include/smp_api_types.h
types/ble_address_with_type.h [new file with mode: 0644]

index 172657f..c4b50ac 100644 (file)
@@ -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"
 
 /*****************************************************************************
index 8729ad1..57a4f1e 100644 (file)
@@ -26,6 +26,7 @@
 #include <list>
 #include <string>
 #include "osi/include/config.h"
+#include "types/ble_address_with_type.h"
 
 static const char BTIF_CONFIG_MODULE[] = "btif_config_module";
 
index 8473612..b2880a6 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "bt_target.h"
 #include "bt_types.h"
+#include "types/ble_address_with_type.h"
 
 /*******************************************************************************
  *  Constants & Macros
index b305f86..ba41909 100644 (file)
@@ -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(
index 53aaf49..07e513f 100644 (file)
@@ -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 {
index ebf5783..ea95c25 100644 (file)
@@ -19,6 +19,7 @@
 #include <cstdint>
 #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 {
index 37ac502..3975597 100644 (file)
@@ -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 {
 
index 4954838..7580a0e 100644 (file)
@@ -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 */
index 4380ed6..e11a7a6 100644 (file)
@@ -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 {
index 57662ae..f5b3467 100644 (file)
@@ -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) */
index 08f0580..f98f2ab 100644 (file)
@@ -22,6 +22,7 @@
 #include <base/callback_forward.h>
 #include <hardware/bt_common_types.h>
 #include <vector>
+#include "types/ble_address_with_type.h"
 
 #define CHNL_MAP_LEN 5
 typedef uint8_t tBTM_BLE_CHNL_MAP[CHNL_MAP_LEN];
index 335a6d8..98e7a92 100644 (file)
@@ -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 (file)
index 0000000..850abb9
--- /dev/null
@@ -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 <cstdint>
+#include <string>
+#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