aboutsummaryrefslogtreecommitdiff
path: root/gd/rust/topshim/src/btm_sec.rs
blob: ec7bbcc1f8bebe5a1c94d5f923d14d96a9f9e62d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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 });
    }
}