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

Commit 9bfe2da1 authored by Chris Manton's avatar Chris Manton
Browse files

btm_log_history: Journal rfcomm connection lifecycles

Bug: 330612352
Test: m .
Flag: EXEMPT, Logging extension
Change-Id: I53a36253666c69f2c3c58b4a169d031912c6b1df
parent 96e60b39
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "stack/include/port_api.h"

#include <base/logging.h>
#include <base/strings/stringprintf.h>
#include <bluetooth/log.h>

#include <cstdint>
@@ -39,6 +40,7 @@
#include "stack/include/bt_hdr.h"
#include "stack/include/bt_types.h"
#include "stack/include/bt_uuid16.h"
#include "stack/include/btm_log_history.h"
#include "stack/rfcomm/rfc_int.h"
#include "types/raw_address.h"

@@ -73,6 +75,10 @@ static const char* result_code_strings[] = {"Success",
                                            "Invalid SCN",
                                            "Unknown result code"};

namespace {
const char kBtmLogTag[] = "RFCOMM";
}  // namespace

/*******************************************************************************
 *
 * Function         RFCOMM_CreateConnectionWithSecurity
@@ -225,9 +231,16 @@ int RFCOMM_CreateConnectionWithSecurity(uint16_t uuid, uint8_t scn,

  // If this is not initiator of the connection need to just wait
  if (p_port->is_server) {
    BTM_LogHistory(kBtmLogTag, bd_addr, "Server started",
                   base::StringPrintf("handle:%hu scn:%hhu dlci:%hhu mtu:%hu",
                                      *p_handle, scn, dlci, mtu));
    return (PORT_SUCCESS);
  }

  BTM_LogHistory(kBtmLogTag, bd_addr, "Connection opened",
                 base::StringPrintf("handle:%hu scn:%hhu dlci:%hhu mtu:%hu",
                                    *p_handle, scn, dlci, mtu));

  // Open will be continued after security checks are passed
  return port_open_continue(p_port);
}
@@ -299,6 +312,14 @@ int RFCOMM_RemoveConnection(uint16_t handle) {
    return (PORT_SUCCESS);
  }

  const RawAddress bd_addr =
      (p_port->rfc.p_mcb) ? (p_port->rfc.p_mcb->bd_addr) : (RawAddress::kEmpty);
  BTM_LogHistory(
      kBtmLogTag, bd_addr, "Connection closed",
      base::StringPrintf("handle:%hu scn:%hhu dlci:%hhu is_server:%s", handle,
                         p_port->scn, p_port->dlci,
                         logbool(p_port->is_server).c_str()));

  p_port->state = PORT_CONNECTION_STATE_CLOSING;

  port_start_close(p_port);
@@ -332,6 +353,14 @@ int RFCOMM_RemoveServer(uint16_t handle) {
  }
  log::info("handle={}", handle);

  const RawAddress bd_addr =
      (p_port->rfc.p_mcb) ? (p_port->rfc.p_mcb->bd_addr) : (RawAddress::kEmpty);
  BTM_LogHistory(
      kBtmLogTag, bd_addr, "Server stopped",
      base::StringPrintf("handle:%hu scn:%hhu dlci:%hhu is_server:%s", handle,
                         p_port->scn, p_port->dlci,
                         logbool(p_port->is_server).c_str()));

  /* this port will be deallocated after closing */
  p_port->keep_port_handle = false;
  p_port->state = PORT_CONNECTION_STATE_CLOSING;