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

Commit a2722353 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

btm: Improve set data length in the controller

With this patch btm keeps track on what TX octects has been suggested to
the controller and does not repeat requestes if not necessary.

This is important for the upcoming MTU improvements

Bug: 257250188
Bug: 239776509
Test: manual
Tag: #feature
Change-Id: I3fe8ed048cd68e25c7e99e5e963bb75cb8dc2767
parent 89caf445
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -631,11 +631,25 @@ tBTM_STATUS BTM_SetBleDataLength(const RawAddress& bd_addr,
    return BTM_ILLEGAL_VALUE;
  }

  LOG_INFO("%s, %d", ADDRESS_TO_LOGGABLE_CSTR(bd_addr), tx_pdu_length);

  auto p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec == NULL) {
    LOG_ERROR("Device %s not found", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    return BTM_UNKNOWN_ADDR;
  }

  if (tx_pdu_length > BTM_BLE_DATA_SIZE_MAX)
    tx_pdu_length = BTM_BLE_DATA_SIZE_MAX;
  else if (tx_pdu_length < BTM_BLE_DATA_SIZE_MIN)
    tx_pdu_length = BTM_BLE_DATA_SIZE_MIN;

  if (p_dev_rec->get_suggested_tx_octets() >= tx_pdu_length) {
    LOG_INFO(" Suggested TX octect already set to controller %d >= %d",
             p_dev_rec->get_suggested_tx_octets(), tx_pdu_length);
    return BTM_SUCCESS;
  }

  uint16_t tx_time = BTM_BLE_DATA_TX_TIME_MAX_LEGACY;

  if (controller_get_interface()->get_bt_version()->hci_version >=
@@ -651,6 +665,7 @@ tBTM_STATUS BTM_SetBleDataLength(const RawAddress& bd_addr,
  if (bluetooth::shim::is_gd_l2cap_enabled()) {
    uint16_t handle = bluetooth::shim::L2CA_GetLeHandle(bd_addr);
    btsnd_hcic_ble_set_data_length(handle, tx_pdu_length, tx_time);
    p_dev_rec->set_suggested_tx_octect(tx_pdu_length);
    return BTM_SUCCESS;
  }

@@ -668,6 +683,7 @@ tBTM_STATUS BTM_SetBleDataLength(const RawAddress& bd_addr,
      tx_time, controller_get_interface()->get_ble_maximum_tx_time());

  btsnd_hcic_ble_set_data_length(hci_handle, tx_pdu_length, tx_time);
  p_dev_rec->set_suggested_tx_octect(tx_pdu_length);

  return BTM_SUCCESS;
}
+1 −0
Original line number Diff line number Diff line
@@ -619,6 +619,7 @@ tBTM_SEC_DEV_REC* btm_sec_allocate_dev_rec(void) {
  p_dev_rec->bond_type = tBTM_SEC_DEV_REC::BOND_TYPE_UNKNOWN;
  p_dev_rec->timestamp = btm_cb.dev_rec_count++;
  p_dev_rec->rmt_io_caps = BTM_IO_CAP_UNKNOWN;
  p_dev_rec->suggested_tx_octets = 0;

  return p_dev_rec;
}
+1 −0
Original line number Diff line number Diff line
@@ -3884,6 +3884,7 @@ void btm_sec_disconnected(uint16_t handle, tHCI_REASON reason,
    p_dev_rec->sec_flags &= ~(BTM_SEC_LE_AUTHENTICATED | BTM_SEC_LE_ENCRYPTED |
                              BTM_SEC_ROLE_SWITCHED);
    p_dev_rec->enc_key_size = 0;
    p_dev_rec->suggested_tx_octets = 0;

    if ((p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN) == 0) {
      p_dev_rec->sec_flags &=
+9 −0
Original line number Diff line number Diff line
@@ -225,6 +225,8 @@ struct tBTM_SEC_DEV_REC {
  void* p_ref_data;
  uint32_t timestamp; /* Timestamp of the last connection   */
  uint16_t hci_handle;     /* Handle to connection when exists   */
  uint16_t suggested_tx_octets; /* Recently suggested tx octects for data length
                                   extension */
  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            */
@@ -358,6 +360,13 @@ struct tBTM_SEC_DEV_REC {
    return sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH;
  }

  /* Data length extension */
  void set_suggested_tx_octect(uint16_t octets) {
    suggested_tx_octets = 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,