diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2021-11-04 07:34:52 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-11-04 07:34:52 +0000 |
commit | 19681cdb683aeb592ba9183177c23b924fecdd94 (patch) | |
tree | fb113c59c440e2d6dfeb586b676bb379b1083650 | |
parent | 61ed9948a2f0d1feff24113946c9545f93163505 (diff) | |
parent | 8ca275530199745bab56b2ce1d9811a749c3abb5 (diff) | |
download | bt-19681cdb683aeb592ba9183177c23b924fecdd94.tar.gz |
Merge "topshim: Add btm_sec shim"
-rw-r--r-- | gd/rust/topshim/Android.bp | 6 | ||||
-rw-r--r-- | gd/rust/topshim/BUILD.gn | 1 | ||||
-rw-r--r-- | gd/rust/topshim/btm_sec/btm_sec_shim.cc | 57 | ||||
-rw-r--r-- | gd/rust/topshim/btm_sec/btm_sec_shim.h | 41 | ||||
-rw-r--r-- | gd/rust/topshim/src/btm_sec.rs | 34 | ||||
-rw-r--r-- | gd/rust/topshim/src/lib.rs | 1 |
6 files changed, 140 insertions, 0 deletions
diff --git a/gd/rust/topshim/Android.bp b/gd/rust/topshim/Android.bp index 1e9677ec0..6a712bf81 100644 --- a/gd/rust/topshim/Android.bp +++ b/gd/rust/topshim/Android.bp @@ -52,6 +52,7 @@ cc_library_static { "gatt/gatt_shim.cc", "hfp/hfp_shim.cc", "controller/controller_shim.cc", + "btm_sec/btm_sec_shim.cc", ], generated_headers: ["libbt_topshim_bridge_header", "cxx-bridge-header"], generated_sources: ["libbt_topshim_bridge_code"], @@ -61,9 +62,12 @@ cc_library_static { include_dirs: [ "system/bt", "system/bt/gd/rust/topshim", + "system/bt/internal_include", "system/bt/include", "system/bt/types", + "system/bt/stack/include", ], + cflags: ["-DHAS_NO_BDROID_BUILDCFG"], host_supported: true, } @@ -78,6 +82,7 @@ gensrcs { "src/profiles/hfp.rs", "src/profiles/gatt.rs", "src/controller.rs", + "src/btm_sec.rs", ], output_extension: "rs.h", export_include_dirs: ["."], @@ -94,6 +99,7 @@ gensrcs { "src/profiles/hfp.rs", "src/profiles/gatt.rs", "src/controller.rs", + "src/btm_sec.rs", ], output_extension: "cc", export_include_dirs: ["."], diff --git a/gd/rust/topshim/BUILD.gn b/gd/rust/topshim/BUILD.gn index bf986cb4b..03b34def7 100644 --- a/gd/rust/topshim/BUILD.gn +++ b/gd/rust/topshim/BUILD.gn @@ -56,6 +56,7 @@ source_set("btif_cxx_bridge_code") { "hfp/hfp_shim.cc", "gatt/gatt_shim.cc", "controller/controller_shim.cc", + "btm_sec/btm_sec_shim.cc", ] deps = [":btif_bridge_header", "//bt/gd:BluetoothGeneratedPackets_h"] diff --git a/gd/rust/topshim/btm_sec/btm_sec_shim.cc b/gd/rust/topshim/btm_sec/btm_sec_shim.cc new file mode 100644 index 000000000..4046d8360 --- /dev/null +++ b/gd/rust/topshim/btm_sec/btm_sec_shim.cc @@ -0,0 +1,57 @@ +/* + * Copyright 2021 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 "gd/rust/topshim/btm_sec/btm_sec_shim.h" + +#include <memory> + +#include "main/shim/btm_api.h" +#include "src/btm_sec.rs.h" +#include "stack/btm/btm_sec.h" +#include "stack/include/hci_error_code.h" +#include "types/bt_transport.h" + +namespace bluetooth { +namespace topshim { +namespace rust { +namespace internal { +static BtmSecIntf* g_btm_sec_intf; +static RawAddress from_rust_address(const RustRawAddress& raddr) { + RawAddress addr; + addr.FromOctets(raddr.address.data()); + return addr; +} +} // namespace internal + +BtmSecIntf::BtmSecIntf() {} +BtmSecIntf::~BtmSecIntf() {} + +void BtmSecIntf::hci_disconnect(RustRawAddress bt_addr) const { + uint16_t handle = shim::BTM_GetHCIConnHandle(internal::from_rust_address(bt_addr), BT_TRANSPORT_BR_EDR); + btm_sec_disconnect(handle, tHCI_STATUS::HCI_ERR_UNDEFINED); +} + +std::unique_ptr<BtmSecIntf> GetBtmSecInterface() { + if (internal::g_btm_sec_intf) std::abort(); + auto btm_sec_intf = std::make_unique<BtmSecIntf>(); + internal::g_btm_sec_intf = btm_sec_intf.get(); + + return btm_sec_intf; +} + +} // namespace rust +} // namespace topshim +} // namespace bluetooth diff --git a/gd/rust/topshim/btm_sec/btm_sec_shim.h b/gd/rust/topshim/btm_sec/btm_sec_shim.h new file mode 100644 index 000000000..11403bccb --- /dev/null +++ b/gd/rust/topshim/btm_sec/btm_sec_shim.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2021 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. + */ +#ifndef GD_RUST_TOPSHIM_BTM_SEC_SHIM +#define GD_RUST_TOPSHIM_BTM_SEC_SHIM + +#include <memory> + +namespace bluetooth { +namespace topshim { +namespace rust { + +struct RustRawAddress; + +class BtmSecIntf { + public: + BtmSecIntf(); + ~BtmSecIntf(); + + void hci_disconnect(RustRawAddress bt_addr) const; +}; + +std::unique_ptr<BtmSecIntf> GetBtmSecInterface(); + +} // namespace rust +} // namespace topshim +} // namespace bluetooth + +#endif
\ No newline at end of file diff --git a/gd/rust/topshim/src/btm_sec.rs b/gd/rust/topshim/src/btm_sec.rs new file mode 100644 index 000000000..ec7bbcc1f --- /dev/null +++ b/gd/rust/topshim/src/btm_sec.rs @@ -0,0 +1,34 @@ +use crate::btif::RawAddress; + +#[cxx::bridge(namespace = bluetooth::topshim::rust)] +mod ffi { + pub struct RustRawAddress { + address: [u8; 6], + } + + unsafe extern "C++" { + include!("btm_sec/btm_sec_shim.h"); + + type BtmSecIntf; + + fn GetBtmSecInterface() -> UniquePtr<BtmSecIntf>; + fn hci_disconnect(self: &BtmSecIntf, bt_addr: RustRawAddress); + } +} + +pub struct BtmSec { + internal: cxx::UniquePtr<ffi::BtmSecIntf>, +} + +unsafe impl Send for BtmSec {} + +impl BtmSec { + pub fn new() -> BtmSec { + let btm_sec_intf = ffi::GetBtmSecInterface(); + BtmSec { internal: btm_sec_intf } + } + + pub fn hci_disconnect(&mut self, address: [u8; 6]) { + self.internal.hci_disconnect(ffi::RustRawAddress { address }); + } +} diff --git a/gd/rust/topshim/src/lib.rs b/gd/rust/topshim/src/lib.rs index c240ba811..e50a82128 100644 --- a/gd/rust/topshim/src/lib.rs +++ b/gd/rust/topshim/src/lib.rs @@ -8,6 +8,7 @@ extern crate bitflags; pub mod bindings; pub mod btif; +pub mod btm_sec; pub mod controller; pub mod profiles; pub mod topstack; |