From 736061d828dacbb43e6eb0c0110f3f6a462e6a7b Mon Sep 17 00:00:00 2001
From: Chris Manton <cmanton@google.com>
Date: Tue, 6 Apr 2021 15:10:23 -0700
Subject: [PATCH] shim: Plumb e/sco connect request

Bug: 183476377
Test: gd/cert/run
Tag: #refactor
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: If14d3bf2f8c632e9007fa846d514a9c3e7bbe18a
---
 system/main/shim/acl_legacy_interface.cc      |  2 ++
 system/main/shim/acl_legacy_interface.h       |  3 +++
 system/main/test/common/mock_stack_btm_sco.cc |  9 +++++++++
 system/stack/btm/btm_sco.cc                   | 14 ++++++++++++++
 system/stack/include/sco_hci_link_interface.h |  5 +++++
 5 files changed, 33 insertions(+)

diff --git a/system/main/shim/acl_legacy_interface.cc b/system/main/shim/acl_legacy_interface.cc
index ed0eec03ed6..089e2f8b335 100644
--- a/system/main/shim/acl_legacy_interface.cc
+++ b/system/main/shim/acl_legacy_interface.cc
@@ -40,6 +40,8 @@ const acl_interface_t GetAclInterface() {
       .connection.le.on_failed = acl_ble_connection_fail,
       .connection.le.on_disconnected = btm_acl_disconnected,
 
+      .connection.sco.on_esco_connect_request = btm_sco_on_esco_connect_request,
+      .connection.sco.on_sco_connect_request = btm_sco_on_sco_connect_request,
       .connection.sco.on_disconnected = btm_sco_on_disconnected,
 
       .link.classic.on_authentication_complete = btm_sec_auth_complete,
diff --git a/system/main/shim/acl_legacy_interface.h b/system/main/shim/acl_legacy_interface.h
index ff0a0764d2e..d146428831b 100644
--- a/system/main/shim/acl_legacy_interface.h
+++ b/system/main/shim/acl_legacy_interface.h
@@ -21,6 +21,7 @@
 #include "stack/include/hci_error_code.h"
 #include "stack/include/hcidefs.h"
 #include "types/ble_address_with_type.h"
+#include "types/class_of_device.h"
 #include "types/hci_role.h"
 #include "types/raw_address.h"
 
@@ -49,6 +50,8 @@ typedef struct {
 } acl_le_connection_interface_t;
 
 typedef struct {
+  void (*on_esco_connect_request)(const RawAddress, const types::ClassOfDevice);
+  void (*on_sco_connect_request)(const RawAddress, const types::ClassOfDevice);
   void (*on_disconnected)(uint16_t handle, tHCI_REASON reason);
 } acl_sco_connection_interface_t;
 
diff --git a/system/main/test/common/mock_stack_btm_sco.cc b/system/main/test/common/mock_stack_btm_sco.cc
index 62c05ab59c5..10e40bf5841 100644
--- a/system/main/test/common/mock_stack_btm_sco.cc
+++ b/system/main/test/common/mock_stack_btm_sco.cc
@@ -28,6 +28,7 @@ extern std::map<std::string, int> mock_function_count_map;
 #include "stack/include/btm_api_types.h"
 #include "stack/include/btm_status.h"
 #include "stack/include/hci_error_code.h"
+#include "types/class_of_device.h"
 #include "types/raw_address.h"
 
 #ifndef UNUSED_ATTR
@@ -111,6 +112,14 @@ void btm_sco_connected(tHCI_STATUS hci_status, const RawAddress& bda,
 void btm_sco_disc_chk_pend_for_modechange(uint16_t hci_handle) {
   mock_function_count_map[__func__]++;
 }
+void btm_sco_on_esco_connect_request(
+    const RawAddress bda, const bluetooth::types::ClassOfDevice cod) {
+  mock_function_count_map[__func__]++;
+}
+void btm_sco_on_sco_connect_request(const RawAddress bda,
+                                    const bluetooth::types::ClassOfDevice cod) {
+  mock_function_count_map[__func__]++;
+}
 void btm_sco_on_disconnected(uint16_t hci_handle, tHCI_REASON reason) {
   mock_function_count_map[__func__]++;
 }
diff --git a/system/stack/btm/btm_sco.cc b/system/stack/btm/btm_sco.cc
index 2c3341dcce9..e992551131d 100644
--- a/system/stack/btm/btm_sco.cc
+++ b/system/stack/btm/btm_sco.cc
@@ -38,6 +38,8 @@
 #include "stack/include/btm_api_types.h"
 #include "stack/include/hci_error_code.h"
 #include "stack/include/hcimsgs.h"
+#include "types/class_of_device.h"
+#include "types/raw_address.h"
 
 extern tBTM_CB btm_cb;
 
@@ -874,6 +876,18 @@ bool btm_sco_removed(uint16_t hci_handle, tHCI_REASON reason) {
   return false;
 }
 
+void btm_sco_on_esco_connect_request(
+    const RawAddress bda, const bluetooth::types::ClassOfDevice cod) {
+  LOG_ERROR("Remote ESCO connect request unimplemented remote:%s",
+            PRIVATE_ADDRESS(bda));
+}
+
+void btm_sco_on_sco_connect_request(const RawAddress bda,
+                                    const bluetooth::types::ClassOfDevice cod) {
+  LOG_ERROR("Remote SCO connect request unimplemented remote:%s",
+            PRIVATE_ADDRESS(bda));
+}
+
 void btm_sco_on_disconnected(uint16_t hci_handle, tHCI_REASON reason) {
   tSCO_CONN* p_sco = btm_cb.sco_cb.get_sco_connection_from_handle(hci_handle);
   if (p_sco == nullptr) {
diff --git a/system/stack/include/sco_hci_link_interface.h b/system/stack/include/sco_hci_link_interface.h
index 6946b5f8819..3a012bb8a16 100644
--- a/system/stack/include/sco_hci_link_interface.h
+++ b/system/stack/include/sco_hci_link_interface.h
@@ -20,6 +20,7 @@
 #include <cstdint>
 
 #include "stack/include/hci_error_code.h"
+#include "types/class_of_device.h"
 #include "types/raw_address.h"
 
 struct tBTM_ESCO_DATA;
@@ -37,3 +38,7 @@ extern void btm_sco_connected(tHCI_STATUS hci_status, const RawAddress& bda,
 extern bool btm_sco_removed(uint16_t hci_handle, tHCI_REASON reason);
 
 void btm_sco_on_disconnected(uint16_t hci_handle, tHCI_REASON reason);
+void btm_sco_on_esco_connect_request(const RawAddress,
+                                     const bluetooth::types::ClassOfDevice);
+void btm_sco_on_sco_connect_request(const RawAddress,
+                                    const bluetooth::types::ClassOfDevice);
-- 
GitLab