OSDN Git Service

Use tBTM_SEC_BLE::tADDRESS_TYPE
authorChris Manton <cmanton@google.com>
Fri, 28 Aug 2020 00:05:36 +0000 (17:05 -0700)
committerChris Manton <cmanton@google.com>
Tue, 1 Sep 2020 23:47:20 +0000 (23:47 +0000)
Towards readable code

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

Change-Id: I5b67eba668a3bb458bf058da80b2dc08e033bd44

stack/acl/ble_acl.cc
stack/acl/btm_acl.cc
stack/btm/btm_ble.cc
stack/btm/btm_ble_addr.cc
stack/btm/btm_ble_connection_establishment.cc
stack/btm/btm_ble_gap.cc
stack/btm/btm_ble_int.h
stack/btm/btm_ble_privacy.cc
stack/btm/security_device_record.h

index 491bd41..f294ed3 100644 (file)
@@ -59,8 +59,8 @@ void acl_ble_enhanced_connection_complete(
                                                 local_rpa);
 
   if (peer_addr_type & BLE_ADDR_TYPE_ID_BIT)
-    btm_ble_refresh_peer_resolvable_private_addr(address_with_type.bda,
-                                                 peer_rpa, BLE_ADDR_RANDOM);
+    btm_ble_refresh_peer_resolvable_private_addr(
+        address_with_type.bda, peer_rpa, tBTM_SEC_BLE::BTM_BLE_ADDR_RRA);
   btm_ble_update_mode_operation(role, &address_with_type.bda, HCI_SUCCESS);
 
   if (role == HCI_ROLE_SLAVE)
index c2a604d..ed0d612 100644 (file)
@@ -243,17 +243,17 @@ bool btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC* p_dev_rec,
   }
 
   switch (p_dev_rec->ble.active_addr_type) {
-    case BTM_BLE_ADDR_PSEUDO:
+    case tBTM_SEC_BLE::BTM_BLE_ADDR_PSEUDO:
       conn_addr = p_dev_rec->bd_addr;
       *p_addr_type = p_dev_rec->ble.ble_addr_type;
       break;
 
-    case BTM_BLE_ADDR_RRA:
+    case tBTM_SEC_BLE::BTM_BLE_ADDR_RRA:
       conn_addr = p_dev_rec->ble.cur_rand_addr;
       *p_addr_type = BLE_ADDR_RANDOM;
       break;
 
-    case BTM_BLE_ADDR_STATIC:
+    case tBTM_SEC_BLE::BTM_BLE_ADDR_STATIC:
       conn_addr = p_dev_rec->ble.identity_addr;
       *p_addr_type = p_dev_rec->ble.identity_addr_type;
       break;
@@ -2432,7 +2432,7 @@ bool acl_refresh_remote_address(const tBTM_SEC_DEV_REC* p_sec_rec,
     return false;
   }
 
-  if (rra_type == BTM_BLE_ADDR_PSEUDO) {
+  if (rra_type == tBTM_SEC_BLE::BTM_BLE_ADDR_PSEUDO) {
     /* use identity address, resolvable_private_addr is empty */
     if (rpa.IsEmpty()) {
       p_acl->active_remote_addr_type = p_sec_rec->ble.identity_addr_type;
index 4fdd349..eb256aa 100644 (file)
@@ -1750,7 +1750,7 @@ void btm_ble_connected(const RawAddress& bda, uint16_t handle, uint8_t enc_mode,
   p_dev_rec->role_master = (role == HCI_ROLE_MASTER) ? true : false;
 
   if (!addr_matched) {
-    p_dev_rec->ble.active_addr_type = BTM_BLE_ADDR_PSEUDO;
+    p_dev_rec->ble.active_addr_type = tBTM_SEC_BLE::BTM_BLE_ADDR_PSEUDO;
   }
   if (!addr_matched && p_dev_rec->ble.ble_addr_type == BLE_ADDR_RANDOM) {
     p_dev_rec->ble.cur_rand_addr = bda;
index 4552030..f171ba3 100644 (file)
@@ -313,9 +313,9 @@ bool btm_random_pseudo_to_identity_addr(RawAddress* random_pseudo,
  *                  connection address.
  *
  ******************************************************************************/
-void btm_ble_refresh_peer_resolvable_private_addr(const RawAddress& pseudo_bda,
-                                                  const RawAddress& rpa,
-                                                  uint8_t rra_type) {
+void btm_ble_refresh_peer_resolvable_private_addr(
+    const RawAddress& pseudo_bda, const RawAddress& rpa,
+    tBTM_SEC_BLE::tADDRESS_TYPE rra_type) {
   tBTM_SEC_DEV_REC* p_sec_rec = btm_find_dev(pseudo_bda);
   if (p_sec_rec == nullptr) {
     LOG_WARN("%s No matching known device in record", __func__);
@@ -324,9 +324,10 @@ void btm_ble_refresh_peer_resolvable_private_addr(const RawAddress& pseudo_bda,
 
   p_sec_rec->ble.cur_rand_addr = rpa;
 
-  if (rra_type == BTM_BLE_ADDR_PSEUDO) {
-    p_sec_rec->ble.active_addr_type =
-        rpa.IsEmpty() ? BTM_BLE_ADDR_STATIC : BTM_BLE_ADDR_RRA;
+  if (rra_type == tBTM_SEC_BLE::BTM_BLE_ADDR_PSEUDO) {
+    p_sec_rec->ble.active_addr_type = rpa.IsEmpty()
+                                          ? tBTM_SEC_BLE::BTM_BLE_ADDR_STATIC
+                                          : tBTM_SEC_BLE::BTM_BLE_ADDR_RRA;
   } else {
     p_sec_rec->ble.active_addr_type = rra_type;
   }
@@ -341,4 +342,3 @@ void btm_ble_refresh_peer_resolvable_private_addr(const RawAddress& pseudo_bda,
     }
   }
 }
-
index 799878f..3160795 100644 (file)
@@ -140,7 +140,7 @@ void btm_ble_conn_complete(uint8_t* p, UNUSED_ATTR uint16_t evt_len,
       if (match_rec) {
         LOG(INFO) << __func__ << ": matched and resolved random address";
         match = true;
-        match_rec->ble.active_addr_type = BTM_BLE_ADDR_RRA;
+        match_rec->ble.active_addr_type = tBTM_SEC_BLE::BTM_BLE_ADDR_RRA;
         match_rec->ble.cur_rand_addr = bda;
         if (!btm_ble_init_pseudo_addr(match_rec, bda)) {
           /* assign the original address to be the current report address */
@@ -176,8 +176,8 @@ void btm_ble_conn_complete(uint8_t* p, UNUSED_ATTR uint16_t evt_len,
       btm_ble_refresh_local_resolvable_private_addr(bda, local_rpa);
 
       if (peer_addr_type & BLE_ADDR_TYPE_ID_BIT)
-        btm_ble_refresh_peer_resolvable_private_addr(bda, peer_rpa,
-                                                     BLE_ADDR_RANDOM);
+        btm_ble_refresh_peer_resolvable_private_addr(
+            bda, peer_rpa, tBTM_SEC_BLE::BTM_BLE_ADDR_RRA);
     }
   } else {
     // Log for non HCI success case
index 6addf28..cce4482 100644 (file)
@@ -1614,7 +1614,7 @@ void btm_ble_process_adv_addr(RawAddress& bda, uint8_t* addr_type) {
   if (!match && BTM_BLE_IS_RESOLVE_BDA(bda)) {
     tBTM_SEC_DEV_REC* match_rec = btm_ble_resolve_random_addr(bda);
     if (match_rec) {
-      match_rec->ble.active_addr_type = BTM_BLE_ADDR_RRA;
+      match_rec->ble.active_addr_type = tBTM_SEC_BLE::BTM_BLE_ADDR_RRA;
       match_rec->ble.cur_rand_addr = bda;
 
       if (btm_ble_init_pseudo_addr(match_rec, bda)) {
index 3125794..1c83f9a 100644 (file)
@@ -143,7 +143,8 @@ extern bool btm_identity_addr_to_random_pseudo_from_address_with_type(
 extern bool btm_random_pseudo_to_identity_addr(RawAddress* random_pseudo,
                                                uint8_t* p_identity_addr_type);
 extern void btm_ble_refresh_peer_resolvable_private_addr(
-    const RawAddress& pseudo_bda, const RawAddress& rra, uint8_t rra_type);
+    const RawAddress& pseudo_bda, const RawAddress& rra,
+    tBTM_SEC_BLE::tADDRESS_TYPE type);
 extern void btm_ble_read_resolving_list_entry_complete(uint8_t* p,
                                                        uint16_t evt_len);
 extern void btm_ble_remove_resolving_list_entry_complete(uint8_t* p,
index c1fe9b1..827eeea 100644 (file)
@@ -336,7 +336,9 @@ void btm_ble_remove_resolving_list_entry_complete(uint8_t* p,
  *
  ******************************************************************************/
 void btm_ble_read_resolving_list_entry_complete(uint8_t* p, uint16_t evt_len) {
-  uint8_t status, rra_type = BTM_BLE_ADDR_PSEUDO;
+  uint8_t status;
+  tBTM_SEC_BLE::tADDRESS_TYPE rra_type =
+      tBTM_SEC_BLE::tADDRESS_TYPE::BTM_BLE_ADDR_PSEUDO;
   RawAddress rra, pseudo_bda;
 
   STREAM_TO_UINT8(status, p);
index cbe5407..36e3f10 100644 (file)
@@ -337,10 +337,13 @@ typedef struct {
   uint8_t in_controller_list; /* in controller resolving list or not */
   uint8_t resolving_list_index;
   RawAddress cur_rand_addr; /* current random address */
-  uint8_t active_addr_type;
-#define BTM_BLE_ADDR_PSEUDO 0 /* address index device record */
-#define BTM_BLE_ADDR_RRA 1    /* cur_rand_addr */
-#define BTM_BLE_ADDR_STATIC 2 /* static_addr  */
+
+  typedef enum : uint8_t {
+    BTM_BLE_ADDR_PSEUDO = 0,
+    BTM_BLE_ADDR_RRA = 1,
+    BTM_BLE_ADDR_STATIC = 2,
+  } tADDRESS_TYPE;
+  tADDRESS_TYPE active_addr_type;
 
   tBTM_LE_KEY_TYPE key_type; /* bit mask of valid key types in record */
   tBTM_SEC_BLE_KEYS keys;    /* LE device security info in slave rode */