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

Commit f3f0202f authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi Committed by En-Shuo Hsu
Browse files

floss: Notify HFP hal on connection/disconnection

When SCO connection or disconnection occurs notify the HFP hal.

Bug: 223685328
Tag: #floss
Test: Verified working on ChromeOS via logs and autotest.
Change-Id: Ic1bcec45b34f19d2046274f451ee73ad09070799
parent 1667430d
Loading
Loading
Loading
Loading
+18 −0
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@
#include "osi/include/allocator.h"
#include "osi/include/allocator.h"
#include "osi/include/log.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
#include "osi/include/osi.h"
#include "stack/btm/btm_sco_hfp_hal.h"
#include "stack/btm/btm_sec.h"
#include "stack/btm/btm_sec.h"
#include "stack/btm/security_device_record.h"
#include "stack/btm/security_device_record.h"
#include "stack/include/acl_api.h"
#include "stack/include/acl_api.h"
@@ -763,6 +764,11 @@ void btm_sco_connected(const RawAddress& bda, uint16_t hci_handle,


      (*p->p_conn_cb)(xx);
      (*p->p_conn_cb)(xx);


      hfp_hal_interface::notify_sco_connection_change(
          bda, /*is_connected=*/true,
          hfp_hal_interface::esco_coding_to_codec(
              p->esco.setup.transmit_coding_format.coding_format));

      bluetooth::audio::sco::open();
      bluetooth::audio::sco::open();


      return;
      return;
@@ -917,11 +923,18 @@ bool btm_sco_removed(uint16_t hci_handle, tHCI_REASON reason) {
  for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) {
  for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) {
    if ((p->state != SCO_ST_UNUSED) && (p->state != SCO_ST_LISTENING) &&
    if ((p->state != SCO_ST_UNUSED) && (p->state != SCO_ST_LISTENING) &&
        (p->hci_handle == hci_handle)) {
        (p->hci_handle == hci_handle)) {
      RawAddress bda(p->esco.data.bd_addr);
      p->state = SCO_ST_UNUSED;
      p->state = SCO_ST_UNUSED;
      p->hci_handle = HCI_INVALID_HANDLE;
      p->hci_handle = HCI_INVALID_HANDLE;
      p->rem_bd_known = false;
      p->rem_bd_known = false;
      p->esco.p_esco_cback = NULL; /* Deregister eSCO callback */
      p->esco.p_esco_cback = NULL; /* Deregister eSCO callback */
      (*p->p_disc_cb)(xx);
      (*p->p_disc_cb)(xx);

      hfp_hal_interface::notify_sco_connection_change(
          bda, /*is_connected=*/false,
          hfp_hal_interface::esco_coding_to_codec(
              p->esco.setup.transmit_coding_format.coding_format));

      LOG_DEBUG("Disconnected SCO link handle:%hu reason:%s", hci_handle,
      LOG_DEBUG("Disconnected SCO link handle:%hu reason:%s", hci_handle,
                hci_reason_code_text(reason).c_str());
                hci_reason_code_text(reason).c_str());
      return true;
      return true;
@@ -976,6 +989,11 @@ void btm_sco_on_disconnected(uint16_t hci_handle, tHCI_REASON reason) {
                 base::StringPrintf("handle:0x%04x reason:%s", hci_handle,
                 base::StringPrintf("handle:0x%04x reason:%s", hci_handle,
                                    hci_reason_code_text(reason).c_str()));
                                    hci_reason_code_text(reason).c_str()));


  hfp_hal_interface::notify_sco_connection_change(
      bd_addr, /*is_connected=*/false,
      hfp_hal_interface::esco_coding_to_codec(
          p_sco->esco.setup.transmit_coding_format.coding_format));

  bluetooth::audio::sco::cleanup();
  bluetooth::audio::sco::cleanup();
}
}


+15 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@
#include <vector>
#include <vector>


#include "bt_target.h"
#include "bt_target.h"
#include "device/include/esco_parameters.h"
#include "raw_address.h"
#include "raw_address.h"


// Used by the Bluetooth stack to get WBS supported and codec, or notify SCO
// Used by the Bluetooth stack to get WBS supported and codec, or notify SCO
@@ -48,6 +49,20 @@ struct bt_codecs {
// Use default packet size for codec if this value is given.
// Use default packet size for codec if this value is given.
constexpr int kDefaultPacketSize = 0;
constexpr int kDefaultPacketSize = 0;


constexpr inline int esco_coding_to_codec(esco_coding_format_t esco_coding) {
  switch (esco_coding) {
    case ESCO_CODING_FORMAT_TRANSPNT:
      return codec::MSBC_TRANSPARENT;
    case ESCO_CODING_FORMAT_MSBC:
      return codec::MSBC;

    // Default to CVSD encoding if unknown format.
    case ESCO_CODING_FORMAT_CVSD:
    default:
      return codec::CVSD;
  }
}

// Initialize the SCO HFP HAL module
// Initialize the SCO HFP HAL module
void init();
void init();