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

Commit a2e71022 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "gatt: Fix handling direct connect" into main

parents 001d87cc c8eb2ee5
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1438,6 +1438,14 @@ bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr,
    } else {
      log::verbose("Connecting without tcb address: {}",
                   ADDRESS_TO_LOGGABLE_CSTR(bd_addr));

      if (p_reg->direct_connect_request.count(bd_addr) == 0) {
        p_reg->direct_connect_request.insert(bd_addr);
      } else {
        log::warn(" {} already added to gatt_if {} direct conn list",
                  ADDRESS_TO_LOGGABLE_CSTR(bd_addr), gatt_if);
      }

      ret = acl_create_le_connection_with_id(gatt_if, bd_addr, addr_type);
    }

+1 −0
Original line number Diff line number Diff line
@@ -197,6 +197,7 @@ typedef struct {
  uint8_t listening{0}; /* if adv for all has been enabled */
  bool eatt_support{false};
  std::string name;
  std::set<RawAddress> direct_connect_request;
} tGATT_REG;

struct tGATT_CLCB;
+10 −0
Original line number Diff line number Diff line
@@ -945,6 +945,16 @@ static void gatt_send_conn_cback(tGATT_TCB* p_tcb) {
    if (apps.find(p_reg->gatt_if) != apps.end())
      gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true);

    if (IS_FLAG_ENABLED(gatt_reconnect_on_bt_on_fix)) {
      if (p_reg->direct_connect_request.count(p_tcb->peer_bda) > 0) {
        gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true);
        log::info(
            "Removing device {} from the direct connect list of gatt_if {} ",
            ADDRESS_TO_LOGGABLE_CSTR(p_tcb->peer_bda), p_reg->gatt_if);
        p_reg->direct_connect_request.erase(p_tcb->peer_bda);
      }
    }

    if (p_reg->app_cb.p_conn_cb) {
      conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if);
      (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, p_tcb->peer_bda, conn_id,
+35 −5
Original line number Diff line number Diff line
@@ -1521,6 +1521,23 @@ void gatt_sr_update_prep_cnt(tGATT_TCB& tcb, tGATT_IF gatt_if, bool is_inc,
bool gatt_cancel_open(tGATT_IF gatt_if, const RawAddress& bda) {
  tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bda, BT_TRANSPORT_LE);
  if (!p_tcb) {
    if (IS_FLAG_ENABLED(gatt_reconnect_on_bt_on_fix)) {
      /* TCB is not allocated when trying to connect under this flag.
       * but device address is storred in the tGATT_REG. Make sure to remove
       * the address from the list when cancel is called.
       */

      tGATT_REG* p_reg = gatt_get_regcb(gatt_if);
      if (!p_reg) {
        log::error("Unable to find registered app gatt_if={}", gatt_if);
      } else {
        log::info("Removing {} from direct list",
                  ADDRESS_TO_LOGGABLE_CSTR(bda));
        p_reg->direct_connect_request.erase(bda);
      }
      return true;
    }

    log::warn("Unable to cancel open for unknown connection gatt_if:{} peer:{}",
              gatt_if, ADDRESS_TO_LOGGABLE_CSTR(bda));
    return true;
@@ -1747,6 +1764,15 @@ static void gatt_le_disconnect_complete_notify_user(const RawAddress& bda,
      (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, bda, conn_id,
                                 kGattDisconnected, reason, transport);
    }

    if (IS_FLAG_ENABLED(gatt_reconnect_on_bt_on_fix)) {
      if (p_reg->direct_connect_request.count(bda) > 0) {
        log::info(
            "Removing device {} from the direct connect list of gatt_if {} ",
            ADDRESS_TO_LOGGABLE_CSTR(bda), p_reg->gatt_if);
        p_reg->direct_connect_request.erase(bda);
      }
    }
  }
}

@@ -1757,15 +1783,19 @@ void gatt_cleanup_upon_disc(const RawAddress& bda, tGATT_DISCONN_REASON reason,

  tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bda, transport);
  if (!p_tcb) {
    if (!IS_FLAG_ENABLED(gatt_reconnect_on_bt_on_fix)) {
      log::error(
          "Disconnect for unknown connection bd_addr:{} reason:{} transport:{}",
          ADDRESS_TO_LOGGABLE_CSTR(bda), gatt_disconnection_reason_text(reason),
          bt_transport_text(transport));

    if (!IS_FLAG_ENABLED(gatt_reconnect_on_bt_on_fix)) {
      return;
    }

    log::info("Connection timeout bd_addr:{} reason:{} transport:{}",
              ADDRESS_TO_LOGGABLE_CSTR(bda),
              gatt_disconnection_reason_text(reason),
              bt_transport_text(transport));

    /* Notify about timeout on direct connect */
    gatt_le_disconnect_complete_notify_user(bda, reason, transport);
    return;
+1 −0
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ TEST_F(StackGattTest, lifecycle_tGATT_REG) {
    memset(reg0.get(), 0, sizeof(tGATT_REG));
    // Restore the complex structure after memset
    memset(&reg1.name, 0, sizeof(std::string));
    memset(&reg1.direct_connect_request, 0, sizeof(std::set<RawAddress>));
    reg1 = {};
    ASSERT_EQ(0, memcmp(reg0.get(), &reg1, actual_sizeof_tGATT_REG()));
  }