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

Commit 9a703ceb authored by Jack He's avatar Jack He
Browse files

L2CAP Socket: Keep track of last allocated socket ID

* Keep track of last allocated socket ID in L2CAP socket stack
* Use last_sock_id + 1 as new IDs when allocating new socket blocks
* The de-dupe and overflow detection mechanism in btsock_l2cap_alloc_l()
  would handle the uint32_t overflow and duplicate ID cases

Test: CtsBluetoothTestCases
Bug: 144148429
Change-Id: Ieb9791ffa34eef919a32e4aff6f4b514859c69c0
parent 64ac98cf
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ static void btsock_l2cap_server_listen(l2cap_socket* sock);
static std::mutex state_lock;

l2cap_socket* socks = NULL;
static uint32_t last_sock_id = 0;
static uid_set_t* uid_set = NULL;
static int pth = -1;

@@ -327,7 +328,7 @@ static l2cap_socket* btsock_l2cap_alloc_l(const char* name,
  sock->next = socks;
  sock->prev = NULL;
  if (socks) socks->prev = sock;
  sock->id = (socks ? socks->id : 0) + 1;
  sock->id = last_sock_id + 1;
  sock->tx_bytes = 0;
  sock->rx_bytes = 0;
  socks = sock;
@@ -345,6 +346,7 @@ static l2cap_socket* btsock_l2cap_alloc_l(const char* name,
    if (!++sock->id) /* no zero IDs allowed */
      sock->id++;
  }
  last_sock_id = sock->id;
  DVLOG(2) << __func__ << " SOCK_LIST: alloc id:" << sock->id;
  return sock;