Loading system/gd/rust/shim/src/bridge.rs +2 −0 Original line number Diff line number Diff line Loading @@ -21,12 +21,14 @@ pub mod ffi { // HCI fn hci_set_acl_callback(hci: &mut Hci, callback: UniquePtr<u8SliceCallback>); fn hci_set_sco_callback(hci: &mut Hci, callback: UniquePtr<u8SliceCallback>); fn hci_set_iso_callback(hci: &mut Hci, callback: UniquePtr<u8SliceCallback>); fn hci_set_evt_callback(hci: &mut Hci, callback: UniquePtr<u8SliceCallback>); fn hci_set_le_evt_callback(hci: &mut Hci, callback: UniquePtr<u8SliceCallback>); fn hci_send_command(hci: &mut Hci, data: &[u8], callback: UniquePtr<u8SliceOnceCallback>); fn hci_send_acl(hci: &mut Hci, data: &[u8]); fn hci_send_sco(hci: &mut Hci, data: &[u8]); fn hci_send_iso(hci: &mut Hci, data: &[u8]); fn hci_register_event(hci: &mut Hci, event: u8); fn hci_register_le_event(hci: &mut Hci, subevent: u8); Loading system/gd/rust/shim/src/hci.rs +17 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ use crate::bridge::ffi; use bluetooth_rs::hci::facade::HciFacadeService; use bt_facade_helpers::U8SliceRunnable; use bt_packets::hci::{AclPacket, CommandPacket, IsoPacket, Packet}; use bt_packets::hci::{AclPacket, CommandPacket, IsoPacket, Packet, ScoPacket}; use std::sync::Arc; use tokio::runtime::Runtime; Loading Loading @@ -62,6 +62,18 @@ pub fn hci_send_acl(hci: &mut Hci, data: &[u8]) { } } pub fn hci_send_sco(hci: &mut Hci, data: &[u8]) { match ScoPacket::parse(data) { Ok(packet) => { let tx = hci.internal.sco_tx.clone(); hci.rt.spawn(async move { tx.send(packet).await.unwrap(); }); } Err(e) => panic!("could not parse sco: {:?} {:02x?}", e, data), } } pub fn hci_send_iso(hci: &mut Hci, data: &[u8]) { match IsoPacket::parse(data) { Ok(packet) => { Loading Loading @@ -92,6 +104,10 @@ pub fn hci_set_acl_callback(hci: &mut Hci, cb: cxx::UniquePtr<ffi::u8SliceCallba hci.internal.acl_rx.stream_runnable(&hci.rt, CallbackWrapper { cb }); } pub fn hci_set_sco_callback(hci: &mut Hci, cb: cxx::UniquePtr<ffi::u8SliceCallback>) { hci.internal.sco_rx.stream_runnable(&hci.rt, CallbackWrapper { cb }); } pub fn hci_set_iso_callback(hci: &mut Hci, cb: cxx::UniquePtr<ffi::u8SliceCallback>) { hci.internal.iso_rx.stream_runnable(&hci.rt, CallbackWrapper { cb }); } Loading system/gd/rust/stack/src/hal/mod.rs +12 −4 Original line number Diff line number Diff line Loading @@ -34,12 +34,10 @@ module! { /// H4 packet header size const H4_HEADER_SIZE: usize = 1; pub use snoop::AclHal; pub use snoop::ControlHal; pub use snoop::IsoHal; pub use snoop::{AclHal, ControlHal, IsoHal, ScoHal}; mod internal { use bt_packets::hci::{AclPacket, CommandPacket, EventPacket, IsoPacket}; use bt_packets::hci::{AclPacket, CommandPacket, EventPacket, IsoPacket, ScoPacket}; use gddi::Stoppable; use std::sync::Arc; use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender}; Loading @@ -53,6 +51,8 @@ mod internal { pub acl_rx: Arc<Mutex<UnboundedReceiver<AclPacket>>>, pub iso_tx: UnboundedSender<IsoPacket>, pub iso_rx: Arc<Mutex<UnboundedReceiver<IsoPacket>>>, pub sco_tx: UnboundedSender<ScoPacket>, pub sco_rx: Arc<Mutex<UnboundedReceiver<ScoPacket>>>, } pub struct InnerHal { Loading @@ -60,6 +60,8 @@ mod internal { pub evt_tx: UnboundedSender<EventPacket>, pub acl_rx: UnboundedReceiver<AclPacket>, pub acl_tx: UnboundedSender<AclPacket>, pub sco_rx: UnboundedReceiver<ScoPacket>, pub sco_tx: UnboundedSender<ScoPacket>, pub iso_rx: UnboundedReceiver<IsoPacket>, pub iso_tx: UnboundedSender<IsoPacket>, } Loading @@ -69,8 +71,10 @@ mod internal { let (cmd_tx, cmd_rx) = unbounded_channel(); let (evt_tx, evt_rx) = unbounded_channel(); let (acl_down_tx, acl_down_rx) = unbounded_channel(); let (sco_down_tx, sco_down_rx) = unbounded_channel(); let (iso_down_tx, iso_down_rx) = unbounded_channel(); let (acl_up_tx, acl_up_rx) = unbounded_channel(); let (sco_up_tx, sco_up_rx) = unbounded_channel(); let (iso_up_tx, iso_up_rx) = unbounded_channel(); ( RawHal { Loading @@ -78,6 +82,8 @@ mod internal { evt_rx: Arc::new(Mutex::new(evt_rx)), acl_tx: acl_down_tx, acl_rx: Arc::new(Mutex::new(acl_up_rx)), sco_tx: sco_down_tx, sco_rx: Arc::new(Mutex::new(sco_up_rx)), iso_tx: iso_down_tx, iso_rx: Arc::new(Mutex::new(iso_up_rx)), }, Loading @@ -86,6 +92,8 @@ mod internal { evt_tx, acl_rx: acl_down_rx, acl_tx: acl_up_tx, sco_rx: sco_down_rx, sco_tx: sco_up_tx, iso_rx: iso_down_rx, iso_tx: iso_up_tx, }, Loading system/gd/rust/stack/src/hal/snoop.rs +28 −1 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ use crate::hal::internal::RawHal; use bt_common::sys_prop; use bt_packets::hci::{AclPacket, CommandPacket, EventPacket, IsoPacket, Packet}; use bt_packets::hci::{AclPacket, CommandPacket, EventPacket, IsoPacket, Packet, ScoPacket}; use bytes::{BufMut, Bytes, BytesMut}; use gddi::{module, part_out, provides, Stoppable}; use log::error; Loading @@ -21,6 +21,7 @@ use tokio::sync::Mutex; struct Hal { control: ControlHal, acl: AclHal, sco: ScoHal, iso: IsoHal, } Loading @@ -42,6 +43,15 @@ pub struct AclHal { pub rx: Arc<Mutex<Receiver<AclPacket>>>, } /// Sco tx/rx #[derive(Clone, Stoppable)] pub struct ScoHal { /// Transmit end pub tx: Sender<ScoPacket>, /// Receive end pub rx: Arc<Mutex<Receiver<ScoPacket>>>, } /// Iso tx/rx #[derive(Clone, Stoppable)] pub struct IsoHal { Loading Loading @@ -135,6 +145,8 @@ async fn provide_snooped_hal(config: SnoopConfig, raw_hal: RawHal, rt: Arc<Runti let (evt_up_tx, evt_up_rx) = channel::<EventPacket>(10); let (acl_down_tx, mut acl_down_rx) = channel::<AclPacket>(10); let (acl_up_tx, acl_up_rx) = channel::<AclPacket>(10); let (sco_down_tx, mut sco_down_rx) = channel::<ScoPacket>(10); let (sco_up_tx, sco_up_rx) = channel::<ScoPacket>(10); let (iso_down_tx, mut iso_down_rx) = channel::<IsoPacket>(10); let (iso_up_tx, iso_up_rx) = channel::<IsoPacket>(10); Loading Loading @@ -170,6 +182,20 @@ async fn provide_snooped_hal(config: SnoopConfig, raw_hal: RawHal, rt: Arc<Runti } logger.log(Type::Acl, Direction::Up, acl.to_bytes()).await; }, Some(sco) = sco_down_rx.recv() => { if let Err(e) = raw_hal.sco_tx.send(sco.clone()) { error!("sco down channel closed {:?}", e); break; } logger.log(Type::Sco, Direction::Down, sco.to_bytes()).await; }, Some(sco) = consume(&raw_hal.sco_rx) => { if let Err(e) = sco_up_tx.send(sco.clone()).await { error!("sco up channel closed {:?}", e); break; } logger.log(Type::Sco, Direction::Up, sco.to_bytes()).await; }, Some(iso) = iso_down_rx.recv() => { if let Err(e) = raw_hal.iso_tx.send(iso.clone()) { error!("iso down channel closed {:?}", e); Loading @@ -192,6 +218,7 @@ async fn provide_snooped_hal(config: SnoopConfig, raw_hal: RawHal, rt: Arc<Runti Hal { control: ControlHal { tx: cmd_down_tx, rx: Arc::new(Mutex::new(evt_up_rx)) }, acl: AclHal { tx: acl_down_tx, rx: Arc::new(Mutex::new(acl_up_rx)) }, sco: ScoHal { tx: sco_down_tx, rx: Arc::new(Mutex::new(sco_up_rx)) }, iso: IsoHal { tx: iso_down_tx, rx: Arc::new(Mutex::new(iso_up_rx)) }, } } Loading system/gd/rust/stack/src/hci/facade.rs +8 −2 Original line number Diff line number Diff line //! HCI layer facade use crate::hal::{AclHal, IsoHal}; use crate::hal::{AclHal, IsoHal, ScoHal}; use crate::hci::{EventRegistry, RawCommandSender}; use bt_common::GrpcFacade; use bt_facade_helpers::RxAdapter; Loading @@ -9,7 +9,8 @@ use bt_facade_proto::empty::Empty; use bt_facade_proto::hci_facade::EventRequest; use bt_facade_proto::hci_facade_grpc::{create_hci_facade, HciFacade}; use bt_packets::hci::{ AclPacket, CommandPacket, EventCode, EventPacket, IsoPacket, LeMetaEventPacket, SubeventCode, AclPacket, CommandPacket, EventCode, EventPacket, IsoPacket, LeMetaEventPacket, ScoPacket, SubeventCode, }; use gddi::{module, provides, Stoppable}; use grpcio::*; Loading @@ -28,6 +29,7 @@ async fn provide_facade( commands: RawCommandSender, events: EventRegistry, acl: AclHal, sco: ScoHal, iso: IsoHal, ) -> HciFacadeService { let (evt_tx, evt_rx) = channel::<EventPacket>(10); Loading @@ -41,6 +43,8 @@ async fn provide_facade( le_evt_rx: RxAdapter::new(le_evt_rx), acl_tx: acl.tx, acl_rx: RxAdapter::from_arc(acl.rx), sco_tx: sco.tx, sco_rx: RxAdapter::from_arc(sco.rx), iso_tx: iso.tx, iso_rx: RxAdapter::from_arc(iso.rx), } Loading @@ -58,6 +62,8 @@ pub struct HciFacadeService { pub le_evt_rx: RxAdapter<LeMetaEventPacket>, pub acl_tx: Sender<AclPacket>, pub acl_rx: RxAdapter<AclPacket>, pub sco_tx: Sender<ScoPacket>, pub sco_rx: RxAdapter<ScoPacket>, pub iso_tx: Sender<IsoPacket>, pub iso_rx: RxAdapter<IsoPacket>, } Loading Loading
system/gd/rust/shim/src/bridge.rs +2 −0 Original line number Diff line number Diff line Loading @@ -21,12 +21,14 @@ pub mod ffi { // HCI fn hci_set_acl_callback(hci: &mut Hci, callback: UniquePtr<u8SliceCallback>); fn hci_set_sco_callback(hci: &mut Hci, callback: UniquePtr<u8SliceCallback>); fn hci_set_iso_callback(hci: &mut Hci, callback: UniquePtr<u8SliceCallback>); fn hci_set_evt_callback(hci: &mut Hci, callback: UniquePtr<u8SliceCallback>); fn hci_set_le_evt_callback(hci: &mut Hci, callback: UniquePtr<u8SliceCallback>); fn hci_send_command(hci: &mut Hci, data: &[u8], callback: UniquePtr<u8SliceOnceCallback>); fn hci_send_acl(hci: &mut Hci, data: &[u8]); fn hci_send_sco(hci: &mut Hci, data: &[u8]); fn hci_send_iso(hci: &mut Hci, data: &[u8]); fn hci_register_event(hci: &mut Hci, event: u8); fn hci_register_le_event(hci: &mut Hci, subevent: u8); Loading
system/gd/rust/shim/src/hci.rs +17 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ use crate::bridge::ffi; use bluetooth_rs::hci::facade::HciFacadeService; use bt_facade_helpers::U8SliceRunnable; use bt_packets::hci::{AclPacket, CommandPacket, IsoPacket, Packet}; use bt_packets::hci::{AclPacket, CommandPacket, IsoPacket, Packet, ScoPacket}; use std::sync::Arc; use tokio::runtime::Runtime; Loading Loading @@ -62,6 +62,18 @@ pub fn hci_send_acl(hci: &mut Hci, data: &[u8]) { } } pub fn hci_send_sco(hci: &mut Hci, data: &[u8]) { match ScoPacket::parse(data) { Ok(packet) => { let tx = hci.internal.sco_tx.clone(); hci.rt.spawn(async move { tx.send(packet).await.unwrap(); }); } Err(e) => panic!("could not parse sco: {:?} {:02x?}", e, data), } } pub fn hci_send_iso(hci: &mut Hci, data: &[u8]) { match IsoPacket::parse(data) { Ok(packet) => { Loading Loading @@ -92,6 +104,10 @@ pub fn hci_set_acl_callback(hci: &mut Hci, cb: cxx::UniquePtr<ffi::u8SliceCallba hci.internal.acl_rx.stream_runnable(&hci.rt, CallbackWrapper { cb }); } pub fn hci_set_sco_callback(hci: &mut Hci, cb: cxx::UniquePtr<ffi::u8SliceCallback>) { hci.internal.sco_rx.stream_runnable(&hci.rt, CallbackWrapper { cb }); } pub fn hci_set_iso_callback(hci: &mut Hci, cb: cxx::UniquePtr<ffi::u8SliceCallback>) { hci.internal.iso_rx.stream_runnable(&hci.rt, CallbackWrapper { cb }); } Loading
system/gd/rust/stack/src/hal/mod.rs +12 −4 Original line number Diff line number Diff line Loading @@ -34,12 +34,10 @@ module! { /// H4 packet header size const H4_HEADER_SIZE: usize = 1; pub use snoop::AclHal; pub use snoop::ControlHal; pub use snoop::IsoHal; pub use snoop::{AclHal, ControlHal, IsoHal, ScoHal}; mod internal { use bt_packets::hci::{AclPacket, CommandPacket, EventPacket, IsoPacket}; use bt_packets::hci::{AclPacket, CommandPacket, EventPacket, IsoPacket, ScoPacket}; use gddi::Stoppable; use std::sync::Arc; use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender}; Loading @@ -53,6 +51,8 @@ mod internal { pub acl_rx: Arc<Mutex<UnboundedReceiver<AclPacket>>>, pub iso_tx: UnboundedSender<IsoPacket>, pub iso_rx: Arc<Mutex<UnboundedReceiver<IsoPacket>>>, pub sco_tx: UnboundedSender<ScoPacket>, pub sco_rx: Arc<Mutex<UnboundedReceiver<ScoPacket>>>, } pub struct InnerHal { Loading @@ -60,6 +60,8 @@ mod internal { pub evt_tx: UnboundedSender<EventPacket>, pub acl_rx: UnboundedReceiver<AclPacket>, pub acl_tx: UnboundedSender<AclPacket>, pub sco_rx: UnboundedReceiver<ScoPacket>, pub sco_tx: UnboundedSender<ScoPacket>, pub iso_rx: UnboundedReceiver<IsoPacket>, pub iso_tx: UnboundedSender<IsoPacket>, } Loading @@ -69,8 +71,10 @@ mod internal { let (cmd_tx, cmd_rx) = unbounded_channel(); let (evt_tx, evt_rx) = unbounded_channel(); let (acl_down_tx, acl_down_rx) = unbounded_channel(); let (sco_down_tx, sco_down_rx) = unbounded_channel(); let (iso_down_tx, iso_down_rx) = unbounded_channel(); let (acl_up_tx, acl_up_rx) = unbounded_channel(); let (sco_up_tx, sco_up_rx) = unbounded_channel(); let (iso_up_tx, iso_up_rx) = unbounded_channel(); ( RawHal { Loading @@ -78,6 +82,8 @@ mod internal { evt_rx: Arc::new(Mutex::new(evt_rx)), acl_tx: acl_down_tx, acl_rx: Arc::new(Mutex::new(acl_up_rx)), sco_tx: sco_down_tx, sco_rx: Arc::new(Mutex::new(sco_up_rx)), iso_tx: iso_down_tx, iso_rx: Arc::new(Mutex::new(iso_up_rx)), }, Loading @@ -86,6 +92,8 @@ mod internal { evt_tx, acl_rx: acl_down_rx, acl_tx: acl_up_tx, sco_rx: sco_down_rx, sco_tx: sco_up_tx, iso_rx: iso_down_rx, iso_tx: iso_up_tx, }, Loading
system/gd/rust/stack/src/hal/snoop.rs +28 −1 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ use crate::hal::internal::RawHal; use bt_common::sys_prop; use bt_packets::hci::{AclPacket, CommandPacket, EventPacket, IsoPacket, Packet}; use bt_packets::hci::{AclPacket, CommandPacket, EventPacket, IsoPacket, Packet, ScoPacket}; use bytes::{BufMut, Bytes, BytesMut}; use gddi::{module, part_out, provides, Stoppable}; use log::error; Loading @@ -21,6 +21,7 @@ use tokio::sync::Mutex; struct Hal { control: ControlHal, acl: AclHal, sco: ScoHal, iso: IsoHal, } Loading @@ -42,6 +43,15 @@ pub struct AclHal { pub rx: Arc<Mutex<Receiver<AclPacket>>>, } /// Sco tx/rx #[derive(Clone, Stoppable)] pub struct ScoHal { /// Transmit end pub tx: Sender<ScoPacket>, /// Receive end pub rx: Arc<Mutex<Receiver<ScoPacket>>>, } /// Iso tx/rx #[derive(Clone, Stoppable)] pub struct IsoHal { Loading Loading @@ -135,6 +145,8 @@ async fn provide_snooped_hal(config: SnoopConfig, raw_hal: RawHal, rt: Arc<Runti let (evt_up_tx, evt_up_rx) = channel::<EventPacket>(10); let (acl_down_tx, mut acl_down_rx) = channel::<AclPacket>(10); let (acl_up_tx, acl_up_rx) = channel::<AclPacket>(10); let (sco_down_tx, mut sco_down_rx) = channel::<ScoPacket>(10); let (sco_up_tx, sco_up_rx) = channel::<ScoPacket>(10); let (iso_down_tx, mut iso_down_rx) = channel::<IsoPacket>(10); let (iso_up_tx, iso_up_rx) = channel::<IsoPacket>(10); Loading Loading @@ -170,6 +182,20 @@ async fn provide_snooped_hal(config: SnoopConfig, raw_hal: RawHal, rt: Arc<Runti } logger.log(Type::Acl, Direction::Up, acl.to_bytes()).await; }, Some(sco) = sco_down_rx.recv() => { if let Err(e) = raw_hal.sco_tx.send(sco.clone()) { error!("sco down channel closed {:?}", e); break; } logger.log(Type::Sco, Direction::Down, sco.to_bytes()).await; }, Some(sco) = consume(&raw_hal.sco_rx) => { if let Err(e) = sco_up_tx.send(sco.clone()).await { error!("sco up channel closed {:?}", e); break; } logger.log(Type::Sco, Direction::Up, sco.to_bytes()).await; }, Some(iso) = iso_down_rx.recv() => { if let Err(e) = raw_hal.iso_tx.send(iso.clone()) { error!("iso down channel closed {:?}", e); Loading @@ -192,6 +218,7 @@ async fn provide_snooped_hal(config: SnoopConfig, raw_hal: RawHal, rt: Arc<Runti Hal { control: ControlHal { tx: cmd_down_tx, rx: Arc::new(Mutex::new(evt_up_rx)) }, acl: AclHal { tx: acl_down_tx, rx: Arc::new(Mutex::new(acl_up_rx)) }, sco: ScoHal { tx: sco_down_tx, rx: Arc::new(Mutex::new(sco_up_rx)) }, iso: IsoHal { tx: iso_down_tx, rx: Arc::new(Mutex::new(iso_up_rx)) }, } } Loading
system/gd/rust/stack/src/hci/facade.rs +8 −2 Original line number Diff line number Diff line //! HCI layer facade use crate::hal::{AclHal, IsoHal}; use crate::hal::{AclHal, IsoHal, ScoHal}; use crate::hci::{EventRegistry, RawCommandSender}; use bt_common::GrpcFacade; use bt_facade_helpers::RxAdapter; Loading @@ -9,7 +9,8 @@ use bt_facade_proto::empty::Empty; use bt_facade_proto::hci_facade::EventRequest; use bt_facade_proto::hci_facade_grpc::{create_hci_facade, HciFacade}; use bt_packets::hci::{ AclPacket, CommandPacket, EventCode, EventPacket, IsoPacket, LeMetaEventPacket, SubeventCode, AclPacket, CommandPacket, EventCode, EventPacket, IsoPacket, LeMetaEventPacket, ScoPacket, SubeventCode, }; use gddi::{module, provides, Stoppable}; use grpcio::*; Loading @@ -28,6 +29,7 @@ async fn provide_facade( commands: RawCommandSender, events: EventRegistry, acl: AclHal, sco: ScoHal, iso: IsoHal, ) -> HciFacadeService { let (evt_tx, evt_rx) = channel::<EventPacket>(10); Loading @@ -41,6 +43,8 @@ async fn provide_facade( le_evt_rx: RxAdapter::new(le_evt_rx), acl_tx: acl.tx, acl_rx: RxAdapter::from_arc(acl.rx), sco_tx: sco.tx, sco_rx: RxAdapter::from_arc(sco.rx), iso_tx: iso.tx, iso_rx: RxAdapter::from_arc(iso.rx), } Loading @@ -58,6 +62,8 @@ pub struct HciFacadeService { pub le_evt_rx: RxAdapter<LeMetaEventPacket>, pub acl_tx: Sender<AclPacket>, pub acl_rx: RxAdapter<AclPacket>, pub sco_tx: Sender<ScoPacket>, pub sco_rx: RxAdapter<ScoPacket>, pub iso_tx: Sender<IsoPacket>, pub iso_rx: RxAdapter<IsoPacket>, } Loading