Loading system/gd/rust/topshim/Android.bp +6 −0 Original line number Diff line number Diff line Loading @@ -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"], Loading @@ -61,9 +62,12 @@ cc_library_static { include_dirs: [ "packages/modules/Bluetooth/system", "packages/modules/Bluetooth/system/gd/rust/topshim", "packages/modules/Bluetooth/system/internal_include", "packages/modules/Bluetooth/system/include", "packages/modules/Bluetooth/system/types", "packages/modules/Bluetooth/system/stack/include", ], cflags: ["-DHAS_NO_BDROID_BUILDCFG"], host_supported: true, } Loading @@ -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: ["."], Loading @@ -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: ["."], Loading system/gd/rust/topshim/BUILD.gn +1 −0 Original line number Diff line number Diff line Loading @@ -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"] Loading system/gd/rust/topshim/btm_sec/btm_sec_shim.cc 0 → 100644 +57 −0 Original line number Diff line number Diff line /* * 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 system/gd/rust/topshim/btm_sec/btm_sec_shim.h 0 → 100644 +41 −0 Original line number Diff line number Diff line /* * 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 system/gd/rust/topshim/src/btm_sec.rs 0 → 100644 +34 −0 Original line number Diff line number Diff line 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 }); } } Loading
system/gd/rust/topshim/Android.bp +6 −0 Original line number Diff line number Diff line Loading @@ -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"], Loading @@ -61,9 +62,12 @@ cc_library_static { include_dirs: [ "packages/modules/Bluetooth/system", "packages/modules/Bluetooth/system/gd/rust/topshim", "packages/modules/Bluetooth/system/internal_include", "packages/modules/Bluetooth/system/include", "packages/modules/Bluetooth/system/types", "packages/modules/Bluetooth/system/stack/include", ], cflags: ["-DHAS_NO_BDROID_BUILDCFG"], host_supported: true, } Loading @@ -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: ["."], Loading @@ -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: ["."], Loading
system/gd/rust/topshim/BUILD.gn +1 −0 Original line number Diff line number Diff line Loading @@ -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"] Loading
system/gd/rust/topshim/btm_sec/btm_sec_shim.cc 0 → 100644 +57 −0 Original line number Diff line number Diff line /* * 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
system/gd/rust/topshim/btm_sec/btm_sec_shim.h 0 → 100644 +41 −0 Original line number Diff line number Diff line /* * 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
system/gd/rust/topshim/src/btm_sec.rs 0 → 100644 +34 −0 Original line number Diff line number Diff line 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 }); } }