Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6aaadcb authored by Sonny Sasaka's avatar Sonny Sasaka Committed by Martin Brabham
Browse files

floss: Modify set_pin and set_passkey interface

The `len` parameter is not useful in the Rust/D-Bus interface since an
the length is already provided in an array data type.

Bug: 202334519
Tag: #floss
Test: Build floss on Linux

Change-Id: I3acd58b996f0f158913e1f5f0ce20b652b6b26d3
parent 57b170b3
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -341,20 +341,14 @@ impl IBluetooth for BluetoothDBus {
        self.client_proxy.method("GetBondState", (BluetoothDevice::to_dbus(device).unwrap(),))
    }

    fn set_pin(&self, device: BluetoothDevice, accept: bool, len: u32, pin_code: Vec<u8>) -> bool {
    fn set_pin(&self, device: BluetoothDevice, accept: bool, pin_code: Vec<u8>) -> bool {
        self.client_proxy
            .method("SetPin", (BluetoothDevice::to_dbus(device).unwrap(), accept, len, pin_code))
            .method("SetPin", (BluetoothDevice::to_dbus(device).unwrap(), accept, pin_code))
    }

    fn set_passkey(
        &self,
        device: BluetoothDevice,
        accept: bool,
        len: u32,
        passkey: Vec<u8>,
    ) -> bool {
    fn set_passkey(&self, device: BluetoothDevice, accept: bool, passkey: Vec<u8>) -> bool {
        self.client_proxy
            .method("SetPasskey", (BluetoothDevice::to_dbus(device).unwrap(), accept, len, passkey))
            .method("SetPasskey", (BluetoothDevice::to_dbus(device).unwrap(), accept, passkey))
    }

    fn set_pairing_confirmation(&self, device: BluetoothDevice, accept: bool) -> bool {
+2 −14
Original line number Diff line number Diff line
@@ -166,24 +166,12 @@ impl IBluetooth for IBluetoothDBus {
    }

    #[dbus_method("SetPin")]
    fn set_pin(
        &self,
        _device: BluetoothDevice,
        _accept: bool,
        _len: u32,
        _pin_code: Vec<u8>,
    ) -> bool {
    fn set_pin(&self, _device: BluetoothDevice, _accept: bool, _pin_code: Vec<u8>) -> bool {
        false
    }

    #[dbus_method("SetPasskey")]
    fn set_passkey(
        &self,
        _device: BluetoothDevice,
        _accept: bool,
        _len: u32,
        _passkey: Vec<u8>,
    ) -> bool {
    fn set_passkey(&self, _device: BluetoothDevice, _accept: bool, _passkey: Vec<u8>) -> bool {
        false
    }

+10 −28
Original line number Diff line number Diff line
@@ -89,16 +89,10 @@ pub trait IBluetooth {
    fn get_bond_state(&self, device: BluetoothDevice) -> u32;

    /// Set pin on bonding device.
    fn set_pin(&self, device: BluetoothDevice, accept: bool, len: u32, pin_code: Vec<u8>) -> bool;
    fn set_pin(&self, device: BluetoothDevice, accept: bool, pin_code: Vec<u8>) -> bool;

    /// Set passkey on bonding device.
    fn set_passkey(
        &self,
        device: BluetoothDevice,
        accept: bool,
        len: u32,
        passkey: Vec<u8>,
    ) -> bool;
    fn set_passkey(&self, device: BluetoothDevice, accept: bool, passkey: Vec<u8>) -> bool;

    /// Confirm that a pairing should be completed on a bonding device.
    fn set_pairing_confirmation(&self, device: BluetoothDevice, accept: bool) -> bool;
@@ -856,7 +850,7 @@ impl IBluetooth for Bluetooth {
        }
    }

    fn set_pin(&self, device: BluetoothDevice, accept: bool, len: u32, pin_code: Vec<u8>) -> bool {
    fn set_pin(&self, device: BluetoothDevice, accept: bool, pin_code: Vec<u8>) -> bool {
        let addr = RawAddress::from_string(device.address.clone());

        if addr.is_none() {
@@ -864,11 +858,6 @@ impl IBluetooth for Bluetooth {
            return false;
        }

        if len as usize != pin_code.len() || len > 16 {
            warn!("Invalid pin code length: {}", len);
            return false;
        }

        let is_bonding = match self.found_devices.get(&device.address) {
            Some(d) => d.bond_state == BtBondState::Bonding,
            None => false,
@@ -882,17 +871,15 @@ impl IBluetooth for Bluetooth {
        let mut btpin: BtPinCode = BtPinCode { pin: [0; 16] };
        btpin.pin.copy_from_slice(pin_code.as_slice());

        self.intf.lock().unwrap().pin_reply(&addr.unwrap(), accept as u8, len as u8, &mut btpin)
            == 0
        self.intf.lock().unwrap().pin_reply(
            &addr.unwrap(),
            accept as u8,
            pin_code.len() as u8,
            &mut btpin,
        ) == 0
    }

    fn set_passkey(
        &self,
        device: BluetoothDevice,
        accept: bool,
        len: u32,
        passkey: Vec<u8>,
    ) -> bool {
    fn set_passkey(&self, device: BluetoothDevice, accept: bool, passkey: Vec<u8>) -> bool {
        let addr = RawAddress::from_string(device.address.clone());

        if addr.is_none() {
@@ -910,11 +897,6 @@ impl IBluetooth for Bluetooth {
            return false;
        }

        if len as usize != passkey.len() || len != 4 {
            warn!("Invalid passkey length: {}", len);
            return false;
        }

        let mut tmp: [u8; 4] = [0; 4];
        tmp.copy_from_slice(passkey.as_slice());
        let passkey = u32::from_ne_bytes(tmp);