Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b818b74c authored by Hui Peng's avatar Hui Peng
Browse files

[Invisalign2] Reorganizes the fields and methods of tBTM_SEC_DEV_REC

Place security related fields together

Bug: 301661850
Test: m com.android.btservices
Flag: EXEMPT, no-op
Change-Id: I6bac080468eb8c2ad32bcf3a0f33a1e878c75f8c
parent 2b0799be
Loading
Loading
Loading
Loading
+95 −91
Original line number Original line Diff line number Diff line
@@ -211,27 +211,80 @@ typedef enum : uint8_t {
 * A record exists for each device authenticated with this device
 * A record exists for each device authenticated with this device
 */
 */
struct tBTM_SEC_DEV_REC {
struct tBTM_SEC_DEV_REC {
  /* Peering bond type */
  /**
  uint32_t required_security_flags_for_pairing;
   * fields used for security
   */
  tBTM_SEC_CALLBACK* p_callback;
  tBTM_SEC_CALLBACK* p_callback;
  void* p_ref_data;
  void* p_ref_data;
  tSECURITY_STATE sec_state; /* Operating state                    */

  tHCI_STATUS sec_status; /* Status in encryption change event  */
  uint16_t sec_flags;     /* Current device security state      */

  uint8_t pin_code_length; /* Length of the pin_code used for pairing */
  uint32_t required_security_flags_for_pairing;
  uint16_t security_required; /* Security required for connection   */

  bool link_key_not_sent; /* link key notification has not been sent waiting for
                             name */
  bool role_central;      /* true if current mode is central (BLE)    */
  uint8_t sm4;            /* BTM_SM4_TRUE, if the peer supports SM4 */
  tBTM_IO_CAP rmt_io_caps;    /* IO capability of the peer device */
  tBTM_AUTH_REQ rmt_auth_req; /* the auth_req flag as in the IO caps rsp evt */
  bool remote_supports_secure_connections;
  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.
                                   */

  // BREDR Link Key Info
  LinkKey link_key;      /* Device link key                    */
  uint8_t link_key_type; /* Type of key used in pairing        */
  uint8_t enc_key_size;  /* current link encryption key size   */

  tBTM_SEC_BLE_KEYS ble_keys; /* LE Link Key Info */

  tBTM_BOND_TYPE bond_type; /* bond type */

  /**
   *  other fields for device management
   */
  RawAddress bd_addr; /* BD_ADDR of the device */
  tBTM_SEC_BLE ble;
  tBTM_BD_NAME sec_bd_name; /* User friendly name of the device. (may be
                               truncated to save space in dev_rec table) */
  DEV_CLASS dev_class;      /* DEV_CLASS of the device            */
  tBT_DEVICE_TYPE device_type;

  uint32_t timestamp; /* Timestamp of the last connection   */
  uint32_t timestamp; /* Timestamp of the last connection   */
  uint16_t hci_handle;     /* Handle to connection when exists   */
  uint16_t hci_handle;     /* Handle to BR/EDR ACL connection when exists */
  uint16_t ble_hci_handle; /* use in DUMO connection */

  uint16_t suggested_tx_octets; /* Recently suggested tx octects for data length
  uint16_t suggested_tx_octets; /* Recently suggested tx octects for data length
                                   extension */
                                   extension */
  uint16_t clock_offset;        /* Latest known clock offset          */
  uint16_t clock_offset;        /* Latest known clock offset          */
  RawAddress bd_addr;      /* BD_ADDR of the device              */
  DEV_CLASS dev_class;     /* DEV_CLASS of the device            */
  LinkKey link_key;        /* Device link key                    */
  tHCI_STATUS sec_status;  /* Status in encryption change event  */


  tBTM_SEC_BLE_KEYS ble_keys; /* LE device security info in peripheral rode */
  // whether the peer device can read GAP characteristics only visible in
  // "discoverable" mode
  bool can_read_discoverable{true};


 public:
  bool remote_features_needed; /* set to true if the local device is in */
  RawAddress RemoteAddress() const { return bd_addr; }
  /* "Secure Connections Only" mode and it receives */
  uint16_t get_br_edr_hci_handle() const { return hci_handle; }
  /* HCI_IO_CAPABILITY_REQUEST_EVT from the peer before */
  /* it knows peer's support for Secure Connections */
  bool remote_supports_hci_role_switch = false;
  bool remote_supports_bredr;
  bool remote_supports_ble;
  bool remote_feature_received = false;

  tBTM_LE_CONN_PRAMS conn_params;
  tREMOTE_VERSION_INFO remote_version_info;


 private:
 private:
  bool is_originator; /* true if device is originating ACL connection */

  // friend functions
  friend bool BTM_SecAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
  friend bool BTM_SecAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
                               const BD_NAME& bd_name, uint8_t* features,
                               const BD_NAME& bd_name, uint8_t* features,
                               LinkKey* p_link_key, uint8_t key_type,
                               LinkKey* p_link_key, uint8_t key_type,
@@ -250,10 +303,27 @@ struct tBTM_SEC_DEV_REC {
  friend tBTM_STATUS btm_sec_bond_by_transport(const RawAddress& bd_addr,
  friend tBTM_STATUS btm_sec_bond_by_transport(const RawAddress& bd_addr,
                                               tBLE_ADDR_TYPE addr_type,
                                               tBLE_ADDR_TYPE addr_type,
                                               tBT_TRANSPORT transport);
                                               tBT_TRANSPORT transport);
  uint8_t pin_code_length; /* Length of the pin_code used for paring */
  friend tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
                                       tBT_TRANSPORT transport,
                                       tBTM_SEC_CALLBACK* p_callback,
                                       void* p_ref_data,
                                       tBTM_BLE_SEC_ACT sec_act);
  friend tBTM_STATUS btm_sec_l2cap_access_req_by_requirement(
      const RawAddress& bd_addr, uint16_t security_required, bool is_originator,
      tBTM_SEC_CALLBACK* p_callback, void* p_ref_data);
  friend tBTM_STATUS btm_sec_mx_access_request(const RawAddress& bd_addr,
                                               bool is_originator,
                                               uint16_t security_required,
                                               tBTM_SEC_CALLBACK* p_callback,
                                               void* p_ref_data);
  friend void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported,
                                        bool sc_supported,
                                        bool hci_role_switch_supported,
                                        bool br_edr_supported,
                                        bool le_supported);


 public:
 public:
  uint16_t sec_flags; /* Current device security state      */
  RawAddress RemoteAddress() const { return bd_addr; }
  bool is_device_authenticated() const {
  bool is_device_authenticated() const {
    return sec_flags & BTM_SEC_AUTHENTICATED;
    return sec_flags & BTM_SEC_AUTHENTICATED;
  }
  }
@@ -318,10 +388,6 @@ struct tBTM_SEC_DEV_REC {
    sec_flags &= ~BTM_SEC_16_DIGIT_PIN_AUTHED;
    sec_flags &= ~BTM_SEC_16_DIGIT_PIN_AUTHED;
  }
  }


  tBTM_BD_NAME sec_bd_name; /* User friendly name of the device. (may be
                               truncated to save space in dev_rec table) */

  tSECURITY_STATE sec_state; /* Operating state                    */
  bool is_security_state_idle() const {
  bool is_security_state_idle() const {
    return sec_state == BTM_SEC_STATE_IDLE;
    return sec_state == BTM_SEC_STATE_IDLE;
  }
  }
@@ -360,74 +426,30 @@ struct tBTM_SEC_DEV_REC {
    return sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH;
    return sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH;
  }
  }


  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;
  }

  uint8_t get_encryption_key_size() const { return enc_key_size; }

  /* Data length extension */
  /* Data length extension */
  void set_suggested_tx_octect(uint16_t octets) {
  void set_suggested_tx_octect(uint16_t octets) {
    suggested_tx_octets = octets;
    suggested_tx_octets = octets;
  }
  }


  uint16_t get_suggested_tx_octets() const { return suggested_tx_octets; }
  uint16_t get_suggested_tx_octets() const { return suggested_tx_octets; }

 private:
  bool is_originator;         /* true if device is originating connection */
  friend tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
                                       tBT_TRANSPORT transport,
                                       tBTM_SEC_CALLBACK* p_callback,
                                       void* p_ref_data,
                                       tBTM_BLE_SEC_ACT sec_act);
  friend tBTM_STATUS btm_sec_l2cap_access_req_by_requirement(
      const RawAddress& bd_addr, uint16_t security_required, bool is_originator,
      tBTM_SEC_CALLBACK* p_callback, void* p_ref_data);
  friend tBTM_STATUS btm_sec_mx_access_request(const RawAddress& bd_addr,
                                               bool is_originator,
                                               uint16_t security_required,
                                               tBTM_SEC_CALLBACK* p_callback,
                                               void* p_ref_data);

 public:
  // whether the peer device can read GAP characteristics only visible in
  // "discoverable" mode
  bool can_read_discoverable{true};

  bool IsLocallyInitiated() const { return is_originator; }
  bool IsLocallyInitiated() const { return is_originator; }

  bool role_central;          /* true if current mode is central     */
  uint16_t security_required; /* Security required for connection   */
  bool link_key_not_sent; /* link key notification has not been sent waiting for
                             name */
  uint8_t link_key_type;  /* Type of key used in pairing   */

  uint8_t sm4;                /* BTM_SM4_TRUE, if the peer supports SM4 */
  tBTM_IO_CAP rmt_io_caps;    /* IO capability of the peer device */
  tBTM_AUTH_REQ rmt_auth_req; /* the auth_req flag as in the IO caps rsp evt */

  bool remote_supports_secure_connections;
  friend void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported,
                                        bool sc_supported,
                                        bool hci_role_switch_supported,
                                        bool br_edr_supported,
                                        bool le_supported);

 public:
  bool SupportsSecureConnections() const {
  bool SupportsSecureConnections() const {
    return remote_supports_secure_connections;
    return remote_supports_secure_connections;
  }
  }


  bool remote_features_needed; /* set to true if the local device is in */
  uint16_t get_br_edr_hci_handle() const { return hci_handle; }
  /* "Secure Connections Only" mode and it receives */
  /* HCI_IO_CAPABILITY_REQUEST_EVT from the peer before */
  /* it knows peer's support for Secure Connections */
  bool remote_supports_hci_role_switch = false;
  bool remote_supports_bredr;
  bool remote_supports_ble;
  bool remote_feature_received = false;

  uint16_t ble_hci_handle; /* use in DUMO connection */
  uint16_t get_ble_hci_handle() const { return ble_hci_handle; }
  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 {
  bool is_device_type_br_edr() const {
    return device_type == BT_DEVICE_TYPE_BREDR;
    return device_type == BT_DEVICE_TYPE_BREDR;
  }
  }
@@ -439,24 +461,6 @@ struct tBTM_SEC_DEV_REC {
  bool is_device_type_has_ble() const {
  bool is_device_type_has_ble() const {
    return device_type & BT_DEVICE_TYPE_BLE;
    return device_type & BT_DEVICE_TYPE_BLE;
  }
  }
  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;

  tREMOTE_VERSION_INFO remote_version_info;


  std::string ToString() const {
  std::string ToString() const {
    return base::StringPrintf(
    return base::StringPrintf(