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

Commit da7c3d4c authored by Chris Manton's avatar Chris Manton
Browse files

Check sco internal API return codes

Bug: 340680275
Test: m .
Flag: EXEMPT, Logging change

Change-Id: Iefd7c693a08f2371919b21d07bf772b0204de4b5
parent 1f95fdfd
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include "audio_hal_interface/hfp_client_interface.h"
#include "bta/ag/bta_ag_int.h"
#include "bta_ag_swb_aptx.h"
#include "btm_status.h"
#include "common/init_flags.h"
#include "hci/controller_interface.h"
#include "internal_include/bt_target.h"
@@ -42,6 +43,7 @@
#include "stack/btm/btm_sco.h"
#include "stack/btm/btm_sco_hfp_hal.h"
#include "stack/include/btm_api.h"
#include "stack/include/btm_client_interface.h"
#include "stack/include/main_thread.h"
#include "types/raw_address.h"

@@ -174,7 +176,9 @@ static void bta_ag_sco_conn_cback(uint16_t sco_idx) {
    /* no match found; disconnect sco, init sco variables */
    bta_ag_cb.sco.p_curr_scb = nullptr;
    bta_ag_cb.sco.state = BTA_AG_SCO_SHUTDOWN_ST;
    BTM_RemoveSco(sco_idx);
    if (get_btm_client_interface().sco.BTM_RemoveSco(sco_idx) != BTM_SUCCESS) {
      log::warn("Unable to remove SCO idx:{}", sco_idx);
    }
  }
}

@@ -554,7 +558,10 @@ void bta_ag_create_sco(tBTA_AG_SCB* p_scb, bool is_orig) {
  if (is_orig) {
    bta_ag_cb.sco.is_local = true;
    /* Set eSCO Mode */
    BTM_SetEScoMode(&params);
    if (get_btm_client_interface().sco.BTM_SetEScoMode(&params) !=
        BTM_SUCCESS) {
      log::warn("Unable to set ESCO mode");
    }
    bta_ag_cb.sco.p_curr_scb = p_scb;
    /* save the current codec as sco_codec can be updated while SCO is open. */
    p_scb->inuse_codec = esco_codec;
@@ -572,7 +579,10 @@ void bta_ag_create_sco(tBTA_AG_SCB* p_scb, bool is_orig) {
        &p_scb->peer_addr, false, params.packet_types, &p_scb->sco_idx,
        bta_ag_sco_conn_cback, bta_ag_sco_disc_cback);
    if (btm_status == BTM_CMD_STARTED) {
      BTM_RegForEScoEvts(p_scb->sco_idx, bta_ag_esco_connreq_cback);
      if (get_btm_client_interface().sco.BTM_RegForEScoEvts(
              p_scb->sco_idx, bta_ag_esco_connreq_cback) != BTM_SUCCESS) {
        log::warn("Unable to register for ESCO events");
      }
    }
    log::debug("Listening AG SCO inx 0x{:04x} status:{} pkt types 0x{:04x}",
               p_scb->sco_idx, btm_status_text(btm_status),
+5 −2
Original line number Diff line number Diff line
@@ -22,10 +22,10 @@
#include <cstdint>

#include "bta/hf_client/bta_hf_client_int.h"
#include "bta/include/bta_ag_api.h"
#include "osi/include/allocator.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/btm_api.h"
#include "stack/include/btm_client_interface.h"

#define BTA_HF_CLIENT_NO_EDR_ESCO                                \
  (ESCO_PKT_TYPES_MASK_NO_2_EV3 | ESCO_PKT_TYPES_MASK_NO_3_EV3 | \
@@ -256,7 +256,10 @@ static void bta_hf_client_sco_create(tBTA_HF_CLIENT_CB* client_cb,

  /* if initiating set current scb and peer bd addr */
  if (is_orig) {
    BTM_SetEScoMode(&params);
    if (get_btm_client_interface().sco.BTM_SetEScoMode(&params) !=
        BTM_SUCCESS) {
      log::warn("Unable to set ESCO mode");
    }
    /* tell sys to stop av if any */
    bta_sys_sco_use(BTA_ID_HS, 1, client_cb->peer_addr);
  }
+24 −7
Original line number Diff line number Diff line
@@ -27,13 +27,13 @@
#include <mutex>

#include "include/hardware/bt_sock.h"
#include "os/log.h"
#include "osi/include/allocator.h"
#include "osi/include/list.h"
#include "osi/include/osi.h"  // INVALID_FD
#include "osi/include/socket.h"
#include "osi/include/thread.h"
#include "stack/include/btm_api.h"
#include "stack/include/btm_client_interface.h"
#include "types/raw_address.h"

// This module provides a socket abstraction for SCO connections to a higher
@@ -89,7 +89,9 @@ bt_status_t btsock_sco_init(thread_t* thread_) {

  thread = thread_;
  enh_esco_params_t params = esco_parameters_for_codec(SCO_CODEC_CVSD_D1, true);
  BTM_SetEScoMode(&params);
  if (get_btm_client_interface().sco.BTM_SetEScoMode(&params) != BTM_SUCCESS) {
    log::warn("Unable to set ESCO parameters");
  }

  return BT_STATUS_SUCCESS;
}
@@ -108,7 +110,10 @@ bt_status_t btsock_sco_listen(int* sock_fd, int /* flags */) {
  sco_socket_t* sco_socket = sco_socket_establish_locked(true, NULL, sock_fd);
  if (!sco_socket) return BT_STATUS_FAIL;

  BTM_RegForEScoEvts(sco_socket->sco_handle, connection_request_cb);
  if (get_btm_client_interface().sco.BTM_RegForEScoEvts(
          sco_socket->sco_handle, connection_request_cb) != BTM_SUCCESS) {
    log::warn("Unable to register for ESCO events");
  }
  listen_sco_socket = sco_socket;

  return BT_STATUS_SUCCESS;
@@ -189,8 +194,12 @@ static sco_socket_t* sco_socket_new(void) {
static void sco_socket_free_locked(sco_socket_t* sco_socket) {
  if (!sco_socket) return;

  if (sco_socket->sco_handle != BTM_INVALID_SCO_INDEX)
    BTM_RemoveSco(sco_socket->sco_handle);
  if (sco_socket->sco_handle != BTM_INVALID_SCO_INDEX) {
    if (get_btm_client_interface().sco.BTM_RemoveSco(sco_socket->sco_handle) !=
        BTM_SUCCESS) {
      log::warn("Unable to remove SCO handle:{}", sco_socket->sco_handle);
    }
  }
  socket_free(sco_socket->socket);
  osi_free(sco_socket);
}
@@ -256,7 +265,12 @@ static void connection_request_cb(tBTM_ESCO_EVT event,
    goto error;
  }

  BTM_RegForEScoEvts(listen_sco_socket->sco_handle, connection_request_cb);
  if (get_btm_client_interface().sco.BTM_RegForEScoEvts(
          listen_sco_socket->sco_handle, connection_request_cb) !=
      BTM_SUCCESS) {
    log::warn("Unable to register for ESCO events handle:{}",
              listen_sco_socket->sco_handle);
  }
  BTM_EScoConnRsp(conn_data->sco_inx, HCI_SUCCESS, NULL);

  return;
@@ -279,7 +293,10 @@ static void connect_completed_cb(uint16_t sco_handle) {
  // app-level
  // interest in the SCO socket.
  if (!sco_socket->socket) {
    BTM_RemoveSco(sco_socket->sco_handle);
    if (get_btm_client_interface().sco.BTM_RemoveSco(sco_socket->sco_handle) !=
        BTM_SUCCESS) {
      log::warn("Unable to remove SCO handle:{}", sco_socket->sco_handle);
    }
    list_remove(sco_sockets, sco_socket);
    return;
  }
+7 −2
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@
#include "stack/include/bt_dev_class.h"
#include "stack/include/btm_api.h"
#include "stack/include/btm_api_types.h"
#include "stack/include/btm_client_interface.h"
#include "stack/include/btm_log_history.h"
#include "stack/include/hci_error_code.h"
#include "stack/include/hcimsgs.h"
@@ -960,7 +961,9 @@ void btm_sco_disc_chk_pend_for_modechange(uint16_t hci_handle) {

    {
      log::debug("Removing SCO Link handle 0x{:04x}", p->hci_handle);
      BTM_RemoveSco(xx);
      if (get_btm_client_interface().sco.BTM_RemoveSco(xx) != BTM_SUCCESS) {
        log::warn("Unable to remove SCO link:{}", xx);
      }
    }
  }
}
@@ -1247,7 +1250,9 @@ void BTM_RemoveSco(const RawAddress& bda) {

  for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) {
    if (p->rem_bd_known && p->esco.data.bd_addr == bda) {
      BTM_RemoveSco(xx);
      if (get_btm_client_interface().sco.BTM_RemoveSco(xx) != BTM_SUCCESS) {
        log::warn("Unable to remove SCO link:{}", xx);
      }
    }
  }
}