OSDN Git Service

Add new api stack/acl/ble_acl::acl_ble__complete
authorChris Manton <cmanton@google.com>
Thu, 27 Aug 2020 18:45:27 +0000 (11:45 -0700)
committerChris Manton <cmanton@google.com>
Sun, 30 Aug 2020 16:45:15 +0000 (09:45 -0700)
Towards readable code

Bug: 163134718
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: Ia7814ef21e2e06197df8354796318f824f21e19c

stack/Android.bp
stack/acl/ble_acl.cc [new file with mode: 0644]
stack/include/ble_acl_interface.h [new file with mode: 0644]

index 90efb3a..fbe5ea1 100644 (file)
@@ -102,6 +102,7 @@ cc_library_static {
         "bnep/bnep_utils.cc",
         "btm/ble_advertiser_hci_interface.cc",
         "acl/btm_acl.cc",
+        "acl/ble_acl.cc",
         "btm/btm_ble.cc",
         "btm/btm_ble_addr.cc",
         "btm/btm_ble_adv_filter.cc",
diff --git a/stack/acl/ble_acl.cc b/stack/acl/ble_acl.cc
new file mode 100644 (file)
index 0000000..d08e66e
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <cstdint>
+
+#include "stack/btm/btm_ble_int.h"
+#include "stack/gatt/connection_manager.h"
+#include "stack/include/acl_api.h"
+#include "stack/include/bt_types.h"
+#include "stack/include/hcidefs.h"
+#include "stack/include/l2cap_hci_link_interface.h"
+
+void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st);  // TODO link internally
+
+void btm_ble_advertiser_notify_terminated_legacy(uint8_t status,
+                                                 uint16_t connection_handle);
+
+void acl_ble_connection_complete(const tBLE_BD_ADDR& address_with_type,
+                                 uint16_t handle, uint8_t role, bool match,
+                                 uint16_t conn_interval, uint16_t conn_latency,
+                                 uint16_t conn_timeout) {
+  connection_manager::on_connection_complete(address_with_type.bda);
+  btm_ble_connected(address_with_type.bda, handle, HCI_ENCRYPT_MODE_DISABLED,
+                    role, address_with_type.type, match);
+
+  l2cble_conn_comp(handle, role, address_with_type.bda, address_with_type.type,
+                   conn_interval, conn_latency, conn_timeout);
+
+  btm_ble_update_mode_operation(role, &address_with_type.bda, HCI_SUCCESS);
+
+  if (role == HCI_ROLE_SLAVE)
+    btm_ble_advertiser_notify_terminated_legacy(HCI_SUCCESS, handle);
+}
+
+void acl_ble_enhanced_connection_complete(
+    const tBLE_BD_ADDR& address_with_type, uint16_t handle, uint8_t role,
+    bool match, uint16_t conn_interval, uint16_t conn_latency,
+    uint16_t conn_timeout, const RawAddress& local_rpa,
+    const RawAddress& peer_rpa, uint8_t peer_addr_type) {
+  connection_manager::on_connection_complete(address_with_type.bda);
+  btm_ble_connected(address_with_type.bda, handle, HCI_ENCRYPT_MODE_DISABLED,
+                    role, address_with_type.type, match);
+
+  l2cble_conn_comp(handle, role, address_with_type.bda, address_with_type.type,
+                   conn_interval, conn_latency, conn_timeout);
+
+  btm_ble_refresh_local_resolvable_private_addr(address_with_type.bda,
+                                                local_rpa);
+
+  if (peer_addr_type & BLE_ADDR_TYPE_ID_BIT)
+    btm_ble_refresh_peer_resolvable_private_addr(address_with_type.bda,
+                                                 peer_rpa, BLE_ADDR_RANDOM);
+  btm_ble_update_mode_operation(role, &address_with_type.bda, HCI_SUCCESS);
+
+  if (role == HCI_ROLE_SLAVE)
+    btm_ble_advertiser_notify_terminated_legacy(HCI_SUCCESS, handle);
+}
+
+void acl_ble_connection_fail(const tBLE_BD_ADDR& address_with_type,
+                             uint16_t handle, bool enhanced, uint8_t status) {
+  if (status != HCI_ERR_ADVERTISING_TIMEOUT) {
+    btm_ble_set_conn_st(BLE_CONN_IDLE);
+    btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, true);
+  } else {
+    btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE;
+    btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true);
+  }
+  btm_ble_update_mode_operation(HCI_ROLE_UNKNOWN, &address_with_type.bda,
+                                status);
+}
diff --git a/stack/include/ble_acl_interface.h b/stack/include/ble_acl_interface.h
new file mode 100644 (file)
index 0000000..b35f767
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "stack/include/bt_types.h"
+
+void acl_ble_connection_complete(const tBLE_BD_ADDR& address_with_type,
+                                 uint16_t handle, uint8_t role, bool match,
+                                 uint16_t conn_interval, uint16_t conn_latency,
+                                 uint16_t conn_timeout);
+void acl_ble_enhanced_connection_complete(
+    const tBLE_BD_ADDR& address_with_type, uint16_t handle, uint8_t role,
+    bool match, uint16_t conn_interval, uint16_t conn_latency,
+    uint16_t conn_timeout, const RawAddress& local_rpa,
+    const RawAddress& peer_rpa, uint8_t peer_addr_type);
+void acl_ble_connection_fail(const tBLE_BD_ADDR& address_with_type,
+                             uint16_t handle, bool enhanced, uint8_t status);