Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rootfs/usr/share/inputplumber/schema/composite_device_v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@
"xbox-series",
"deck",
"ds5",
"ds5-usb",
"ds5-bt",
"ds5-edge",
"ds5-edge-usb",
"ds5-edge-bt",
"touchpad",
"touchscreen"
]
Expand Down
55 changes: 55 additions & 0 deletions src/drivers/dualsense/hid_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ pub enum PackedInputDataReport {
}

impl PackedInputDataReport {
pub fn new_bt() -> Self {
Self::Bluetooth(BluetoothPackedInputDataReport::new())
}

pub fn new_usb() -> Self {
Self::Usb(USBPackedInputDataReport::new())
}

pub fn unpack(buf: &[u8], size: usize) -> Result<Self, Box<dyn Error + Send + Sync>> {
let report_id = buf[0];
match report_id {
Expand Down Expand Up @@ -544,6 +552,12 @@ pub struct BluetoothPackedInputDataReport {
pub bt_crc_fail_count: u8,
}

impl BluetoothPackedInputDataReport {
pub fn new() -> Self {
Self::default()
}
}

impl Default for BluetoothPackedInputDataReport {
fn default() -> Self {
Self {
Expand Down Expand Up @@ -794,3 +808,44 @@ impl Default for UsbPackedOutputReportShort {
}
}
}

// When using bluetooth, the first byte after the reportID is uint8_t seq_tag,
// while the next one is uint8_t tag, following bytes are the same as USB.
#[derive(PackedStruct, Debug, Copy, Clone, PartialEq)]
#[packed_struct(bit_numbering = "msb0", size_bytes = "78")]
pub struct BluetoothPackedOutputReport {
// byte 0
#[packed_field(bytes = "0")]
pub report_id: u8, // Report ID (always 0x31)

// byte 1
#[packed_field(bytes = "1")]
pub seq_tag: u8,

// byte 2
#[packed_field(bytes = "2")]
pub tag: u8,

// byte 3-49
#[packed_field(bytes = "3..=49")]
pub state: SetStatePackedOutputData,

#[packed_field(bytes = "50..=73", endian = "lsb")]
pub reserved: [u8; 24],

#[packed_field(bytes = "74..=77", endian = "lsb")]
pub crc32: u32,
}

impl Default for BluetoothPackedOutputReport {
fn default() -> Self {
Self {
report_id: 0x31,
seq_tag: 0x00,
tag: 0x00,
state: Default::default(),
reserved: Default::default(),
crc32: Default::default(),
}
}
}
49 changes: 47 additions & 2 deletions src/input/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,15 +1246,60 @@ impl Manager {
}
};

// If the device is a bluetooth device, check that it's a REAL
// bluetooth device or if it's an emulated bluetooth device.
let mut is_physical_bluetooth = false;
if is_bluetooth {
let uniq = device.uniq();
let object_manager =
zbus::fdo::ObjectManagerProxy::builder(self.dbus.connection())
.destination("org.bluez")?
.path("/")?
.build()
.await?;
let objects: ManagedObjects = object_manager.get_managed_objects().await?;

// Check each dbus object for a connected device
for (path, obj) in objects.iter() {
// Only consider device objects
if !obj.contains_key("org.bluez.Device1") {
log::trace!("{path} does not have org.bluez.Device1 interface");
continue;
}

// Get a reference to the device
let bt_device = Device1Proxy::builder(self.dbus.connection())
.destination("org.bluez")?
.path(path)?
.build()
.await?;

// Only consider connected bluetooth devices
if !bt_device.connected().await? {
continue;
}

// Check to see if the 'uniq' field matches the bluetooth addr
let address = bt_device.address().await?;
log::debug!(
"Checking if virtual device {uniq} is bluetooth device: {address}"
);
if uniq.to_lowercase() == address.to_lowercase() {
is_physical_bluetooth = true;
break;
}
}
}

// Some virtual gamepads we DO want to manage
let device_name = device.get_attribute_from_tree("name").unwrap_or_default();
let is_whitelisted = VIRT_DEVICE_WHITELIST.contains(&device_name.as_str());

if !is_bluetooth && !is_whitelisted {
if !is_physical_bluetooth && !is_whitelisted {
log::debug!("{dev_name} ({dev_sysname}) is virtual, skipping consideration for {dev_path}");
notify_device_added = false;
}
if is_bluetooth {
if is_physical_bluetooth {
log::debug!("{dev_name} ({dev_sysname}) is a virtual device node for a bluetooth device. Treating as real - {dev_path}");
}
if is_whitelisted {
Expand Down
Loading