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

Commit e743bc9a authored by Zining Jiang's avatar Zining Jiang Committed by Gerrit Code Review
Browse files

Merge "RFCOMM: optimize rfcomm dump log" into main

parents f2884f36 a628cb45
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -48,5 +48,6 @@ const btsock_interface_t* btif_sock_get_interface(void);
bt_status_t btif_sock_init(uid_set_t* uid_set);
void btif_sock_cleanup(void);

void btif_sock_connection_logger(int state, int role, const RawAddress& addr);
void btif_sock_connection_logger(int state, int role, const RawAddress& addr,
                                 int channel, const char* server_name);
void btif_sock_dump(int fd);
+23 −11
Original line number Diff line number Diff line
@@ -76,6 +76,8 @@ struct SockConnectionEvent {
  RawAddress addr;
  int state;
  int role;
  int channel;
  char server_name[64];
  struct timespec timestamp;

  void dump(const int fd);
@@ -156,9 +158,10 @@ void btif_sock_cleanup(void) {
  thread = NULL;
}

void btif_sock_connection_logger(int state, int role, const RawAddress& addr) {
  LOG_INFO("address=%s, state=%d, role=%d", ADDRESS_TO_LOGGABLE_CSTR(addr),
           state, role);
void btif_sock_connection_logger(int state, int role, const RawAddress& addr,
                                 int channel, const char* server_name) {
  LOG_INFO("address=%s, state=%d, role=%d, server_name=%s, channel=%d",
           ADDRESS_TO_LOGGABLE_CSTR(addr), state, role, server_name, channel);

  uint8_t index = logger_index++ % SOCK_LOGGER_SIZE_MAX;

@@ -167,13 +170,20 @@ void btif_sock_connection_logger(int state, int role, const RawAddress& addr) {
      .addr = addr,
      .state = state,
      .role = role,
      .channel = channel,
      .server_name = {'\0'},
  };

  strncpy(connection_logger[index].server_name, server_name,
          sizeof(connection_logger[index].server_name) - 1);
  clock_gettime(CLOCK_REALTIME, &connection_logger[index].timestamp);
}

void btif_sock_dump(int fd) {
  dprintf(fd, "\nSocket Events: \n");
  dprintf(fd, "  Time        \tAddress          \tState             \tRole\n");
  dprintf(fd,
          "  Time        \tAddress          \tState             \tRole"
          "              \tChannel   \tServerName\n");

  const uint8_t head = logger_index.load() % SOCK_LOGGER_SIZE_MAX;

@@ -234,8 +244,9 @@ void SockConnectionEvent::dump(const int fd) {
      break;
  }

  dprintf(fd, "  %s\t%s\t%s   \t%s\n", eventtime,
          ADDRESS_TO_LOGGABLE_CSTR(addr), str_state, str_role);
  dprintf(fd, "  %s\t%s\t%s   \t%s      \t%d         \t%s\n", eventtime,
          ADDRESS_TO_LOGGABLE_CSTR(addr), str_state, str_role, channel,
          server_name);
}

static bt_status_t btsock_control_req(uint8_t dlci, const RawAddress& bd_addr,
@@ -258,8 +269,6 @@ static bt_status_t btsock_listen(btsock_type_t type, const char* service_name,
  bt_status_t status = BT_STATUS_FAIL;
  int original_channel = channel;

  btif_sock_connection_logger(SOCKET_CONNECTION_STATE_LISTENING,
                              SOCKET_ROLE_LISTEN, RawAddress::kEmpty);
  log_socket_connection_state(RawAddress::kEmpty, 0, type,
                              android::bluetooth::SocketConnectionstateEnum::
                                  SOCKET_CONNECTION_STATE_LISTENING,
@@ -302,7 +311,8 @@ static bt_status_t btsock_listen(btsock_type_t type, const char* service_name,
  }
  if (status != BT_STATUS_SUCCESS) {
    btif_sock_connection_logger(SOCKET_CONNECTION_STATE_DISCONNECTED,
                                SOCKET_ROLE_LISTEN, RawAddress::kEmpty);
                                SOCKET_ROLE_LISTEN, RawAddress::kEmpty, channel,
                                service_name);
    log_socket_connection_state(RawAddress::kEmpty, 0, type,
                                android::bluetooth::SocketConnectionstateEnum::
                                    SOCKET_CONNECTION_STATE_DISCONNECTED,
@@ -324,7 +334,8 @@ static bt_status_t btsock_connect(const RawAddress* bd_addr, btsock_type_t type,
  bt_status_t status = BT_STATUS_FAIL;

  btif_sock_connection_logger(SOCKET_CONNECTION_STATE_CONNECTING,
                              SOCKET_ROLE_CONNECTION, *bd_addr);
                              SOCKET_ROLE_CONNECTION, *bd_addr, channel,
                              uuid->ToString().c_str());
  log_socket_connection_state(*bd_addr, 0, type,
                              android::bluetooth::SocketConnectionstateEnum::
                                  SOCKET_CONNECTION_STATE_CONNECTING,
@@ -370,7 +381,8 @@ static bt_status_t btsock_connect(const RawAddress* bd_addr, btsock_type_t type,
  }
  if (status != BT_STATUS_SUCCESS) {
    btif_sock_connection_logger(SOCKET_CONNECTION_STATE_DISCONNECTED,
                                SOCKET_ROLE_CONNECTION, *bd_addr);
                                SOCKET_ROLE_CONNECTION, *bd_addr, channel,
                                uuid->ToString().c_str());
    log_socket_connection_state(*bd_addr, 0, type,
                                android::bluetooth::SocketConnectionstateEnum::
                                    SOCKET_CONNECTION_STATE_DISCONNECTED,
+9 −5
Original line number Diff line number Diff line
@@ -208,7 +208,8 @@ static void btsock_l2cap_free_l(l2cap_socket* sock) {

  btif_sock_connection_logger(
      SOCKET_CONNECTION_STATE_DISCONNECTED,
      sock->server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, sock->addr);
      sock->server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, sock->addr,
      sock->channel, sock->name);

  // Whenever a socket is freed, the connection must be dropped
  log_socket_connection_state(
@@ -413,7 +414,8 @@ static void on_srv_l2cap_listen_started(tBTA_JV_L2CAP_START* p_start,

  btif_sock_connection_logger(
      SOCKET_CONNECTION_STATE_LISTENING,
      sock->server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, sock->addr);
      sock->server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, sock->addr,
      sock->channel, sock->name);

  log_socket_connection_state(
      sock->addr, sock->id, sock->is_le_coc ? BTSOCK_L2CAP_LE : BTSOCK_L2CAP,
@@ -481,7 +483,7 @@ static void on_srv_l2cap_psm_connect_l(tBTA_JV_L2CAP_OPEN* p_open,
  btif_sock_connection_logger(
      SOCKET_CONNECTION_STATE_CONNECTED,
      accept_rs->server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION,
      accept_rs->addr);
      accept_rs->addr, accept_rs->channel, accept_rs->name);

  log_socket_connection_state(
      accept_rs->addr, accept_rs->id,
@@ -525,7 +527,8 @@ static void on_cl_l2cap_psm_connect_l(tBTA_JV_L2CAP_OPEN* p_open,

  btif_sock_connection_logger(
      SOCKET_CONNECTION_STATE_CONNECTED,
      sock->server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, sock->addr);
      sock->server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, sock->addr,
      sock->channel, sock->name);

  log_socket_connection_state(
      sock->addr, sock->id, sock->is_le_coc ? BTSOCK_L2CAP_LE : BTSOCK_L2CAP,
@@ -581,7 +584,8 @@ static void on_l2cap_close(tBTA_JV_L2CAP_CLOSE* p_close, uint32_t id) {

  btif_sock_connection_logger(
      SOCKET_CONNECTION_STATE_DISCONNECTING,
      sock->server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, sock->addr);
      sock->server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, sock->addr,
      sock->channel, sock->name);

  log_socket_connection_state(
      sock->addr, sock->id, sock->is_le_coc ? BTSOCK_L2CAP_LE : BTSOCK_L2CAP,
+11 −6
Original line number Diff line number Diff line
@@ -228,6 +228,7 @@ static rfc_slot_t* alloc_rfc_slot(const RawAddress* addr, const char* name,
  }
  slot->id = rfc_slot_id;
  slot->f.server = server;
  slot->role = server;
  slot->tx_bytes = 0;
  slot->rx_bytes = 0;
  return slot;
@@ -422,8 +423,10 @@ static void cleanup_rfc_slot(rfc_slot_t* slot) {
    close(slot->fd);
    btif_sock_connection_logger(
        SOCKET_CONNECTION_STATE_DISCONNECTED,
        slot->f.server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION,
        slot->addr);
        slot->role ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, slot->addr,
        slot->scn,
        slot->role ? slot->service_name
                   : slot->service_uuid.ToString().c_str());
    log_socket_connection_state(
        slot->addr, slot->id, BTSOCK_RFCOMM,
        android::bluetooth::SOCKET_CONNECTION_STATE_DISCONNECTED,
@@ -517,7 +520,8 @@ static void on_srv_rfc_listen_started(tBTA_JV_RFCOMM_START* p_start,
  slot->rfc_handle = p_start->handle;
  btif_sock_connection_logger(
      SOCKET_CONNECTION_STATE_LISTENING,
      slot->f.server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, slot->addr);
      slot->role ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, slot->addr,
      slot->scn, slot->service_name);
  log_socket_connection_state(slot->addr, slot->id, BTSOCK_RFCOMM,
                              android::bluetooth::SocketConnectionstateEnum::
                                  SOCKET_CONNECTION_STATE_LISTENING,
@@ -543,8 +547,8 @@ static uint32_t on_srv_rfc_connect(tBTA_JV_RFCOMM_SRV_OPEN* p_open,

  btif_sock_connection_logger(
      SOCKET_CONNECTION_STATE_CONNECTED,
      accept_rs->f.server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION,
      accept_rs->addr);
      accept_rs->role ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION,
      accept_rs->addr, accept_rs->scn, accept_rs->service_name);
  log_socket_connection_state(
      accept_rs->addr, accept_rs->id, BTSOCK_RFCOMM,
      android::bluetooth::SOCKET_CONNECTION_STATE_CONNECTED, 0, 0,
@@ -584,7 +588,8 @@ static void on_cli_rfc_connect(tBTA_JV_RFCOMM_OPEN* p_open, uint32_t id) {

  btif_sock_connection_logger(
      SOCKET_CONNECTION_STATE_CONNECTED,
      slot->f.server ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, slot->addr);
      slot->role ? SOCKET_ROLE_LISTEN : SOCKET_ROLE_CONNECTION, slot->addr,
      slot->scn, slot->service_uuid.ToString().c_str());
  log_socket_connection_state(
      slot->addr, slot->id, BTSOCK_RFCOMM,
      android::bluetooth::SOCKET_CONNECTION_STATE_CONNECTED, 0, 0,