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

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

bta_gattc: Fix handling disconnect

Each of the p_clcb has the pointer to the server cache which keeps
number of clients, mtu, state etc.
Till now, state of the server was cleared when all p_clcb got
deallocated which usually happens on link disconnection.
However, if any of the client creates background connect, the p_clcb is
created and server would stay in the outdated state.
This leads to use invalid MTU after reconnection.

Bug: 263359541
Test: atest BluetoothInstrumentationTests
Test: manual connect/disconnect GATT devices
Tag: #feature
Merged-In: I9d4a3b6d2c334af144e571025298fedea54025cd
Change-Id: I9d4a3b6d2c334af144e571025298fedea54025cd
(cherry picked from commit 073937b7)
parent edf576ff
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -630,6 +630,18 @@ void bta_gattc_close(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data) {
    }
  }

  if (p_data->hdr.event == BTA_GATTC_INT_DISCONN_EVT) {
    /* Since link has been disconnected by and it is possible that here are
     * already some new p_clcb created for the background connect, the number of
     * p_srcb->num_clcb is NOT 0. This will prevent p_srcb to be cleared inside
     * the bta_gattc_clcb_dealloc.
     *
     * In this point of time, we know that link does not exist, so let's make
     * sure the connection state, mtu and database is cleared.
     */
    bta_gattc_server_disconnected(p_clcb->p_srcb);
  }

  bta_gattc_clcb_dealloc(p_clcb);

  if (p_data->hdr.event == BTA_GATTC_API_CLOSE_EVT) {
+1 −0
Original line number Diff line number Diff line
@@ -423,6 +423,7 @@ extern tBTA_GATTC_CLCB* bta_gattc_clcb_alloc(tGATT_IF client_if,
                                             const RawAddress& remote_bda,
                                             tBT_TRANSPORT transport);
extern void bta_gattc_clcb_dealloc(tBTA_GATTC_CLCB* p_clcb);
extern void bta_gattc_server_disconnected(tBTA_GATTC_SERV* p_srcb);
extern tBTA_GATTC_CLCB* bta_gattc_find_alloc_clcb(tGATT_IF client_if,
                                                  const RawAddress& remote_bda,
                                                  tBT_TRANSPORT transport);
+20 −0
Original line number Diff line number Diff line
@@ -189,6 +189,26 @@ tBTA_GATTC_CLCB* bta_gattc_find_alloc_clcb(tGATT_IF client_if,
  return p_clcb;
}

/*******************************************************************************
 *
 * Function         bta_gattc_server_disconnected
 *
 * Description      Set server cache disconnected
 *
 * Returns          pointer to the srcb
 *
 ******************************************************************************/
void bta_gattc_server_disconnected(tBTA_GATTC_SERV* p_srcb) {
  if (p_srcb && p_srcb->connected) {
    p_srcb->connected = false;
    p_srcb->state = BTA_GATTC_SERV_IDLE;
    p_srcb->mtu = 0;

    // clear reallocating
    p_srcb->gatt_database.Clear();
  }
}

/*******************************************************************************
 *
 * Function         bta_gattc_clcb_dealloc