OSDN Git Service

Add getters to stack/btm/security_device_record::tBTM_SEC_DEV_REC
authorChris Manton <cmanton@google.com>
Mon, 7 Sep 2020 16:37:31 +0000 (09:37 -0700)
committerChris Manton <cmanton@google.com>
Fri, 18 Sep 2020 17:50:07 +0000 (10:50 -0700)
Towards readable code

Bug: 163134718
Tag: #refactor
Test: compile & verify basic functions working
Test: act.py -tc BleCocTest

Change-Id: Ia024a6977d606714f7edc58ded09f82a95703324

stack/btm/security_device_record.h

index 601613b..08cce6a 100644 (file)
@@ -173,6 +173,37 @@ typedef struct {
 #define BTM_SEC_STATE_DISCONNECTING_BOTH 9 /* disconnecting BR/EDR and BLE */
 
   uint8_t sec_state;          /* Operating state                    */
+  bool is_security_state_idle() const {
+    return sec_state == BTM_SEC_STATE_IDLE;
+  }
+  bool is_security_state_authenticating() const {
+    return sec_state == BTM_SEC_STATE_AUTHENTICATING;
+  }
+  bool is_security_state_encrypting() const {
+    return sec_state == BTM_SEC_STATE_ENCRYPTING;
+  }
+  bool is_security_state_getting_name() const {
+    return sec_state == BTM_SEC_STATE_GETTING_NAME;
+  }
+  bool is_security_state_authorizing() const {
+    return sec_state == BTM_SEC_STATE_AUTHORIZING;
+  }
+  bool is_security_state_switching_role() const {
+    return sec_state == BTM_SEC_STATE_SWITCHING_ROLE;
+  }
+  bool is_security_state_disconnecting() const {
+    return sec_state == BTM_SEC_STATE_DISCONNECTING;
+  }
+  bool is_security_state_wait_for_encryption() const {
+    return sec_state == BTM_SEC_STATE_DELAY_FOR_ENC;
+  }
+  bool is_security_state_ble_disconnecting() const {
+    return sec_state == BTM_SEC_STATE_DISCONNECTING_BLE;
+  }
+  bool is_security_state_br_edr_and_ble() const {
+    return sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH;
+  }
+
   bool is_originator;         /* true if device is originating connection */
   bool role_master;           /* true if current mode is master     */
   uint16_t security_required; /* Security required for connection   */
@@ -207,14 +238,33 @@ typedef struct {
   /* it knows peer's support for Secure Connections */
 
   uint16_t ble_hci_handle; /* use in DUMO connection */
+  uint16_t get_ble_hci_handle() const { return ble_hci_handle; }
+
   uint8_t enc_key_size;    /* current link encryption key size */
+  uint8_t get_encryption_key_size() const { return enc_key_size; }
+
   tBT_DEVICE_TYPE device_type;
+  bool is_device_type_br_edr() const {
+    return device_type == BT_DEVICE_TYPE_BREDR;
+  }
+  bool is_device_type_ble() const { return device_type == BT_DEVICE_TYPE_BLE; }
+  bool is_device_type_dual_mode() const {
+    return device_type == BT_DEVICE_TYPE_DUMO;
+  }
+
   bool new_encryption_key_is_p256; /* Set to true when the newly generated LK
                                    ** is generated from P-256.
                                    ** Link encrypted with such LK can be used
                                    ** for SM over BR/EDR.
                                    */
   tBTM_BOND_TYPE bond_type; /* peering bond type */
+  bool is_bond_type_unknown() const { return bond_type == BOND_TYPE_UNKNOWN; }
+  bool is_bond_type_persistent() const {
+    return bond_type == BOND_TYPE_PERSISTENT;
+  }
+  bool is_bond_type_temporary() const {
+    return bond_type == BOND_TYPE_TEMPORARY;
+  }
 
   tBTM_SEC_BLE ble;
   tBTM_LE_CONN_PRAMS conn_params;
@@ -223,5 +273,14 @@ typedef struct {
 #define BTM_SEC_RS_PENDING 1     /* Role Switch in progress */
 #define BTM_SEC_DISC_PENDING 2   /* Disconnect is pending */
   uint8_t rs_disc_pending;
+  bool is_role_switch_idle() const {
+    return rs_disc_pending == BTM_SEC_RS_NOT_PENDING;
+  }
+  bool is_role_switch_pending() const {
+    return rs_disc_pending == BTM_SEC_RS_PENDING;
+  }
+  bool is_role_switch_disconnecting() const {
+    return rs_disc_pending == BTM_SEC_DISC_PENDING;
+  }
 
 } tBTM_SEC_DEV_REC;