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

Commit 40d93fb6 authored by Archie Pusaka's avatar Archie Pusaka Committed by Automerger Merge Worker
Browse files

Merge "Floss: Support connecting and listening on LE L2CAP socket" am: d3e9b02b am: 5e1c2e85

parents c010b79f 5e1c2e85
Loading
Loading
Loading
Loading
+39 −6
Original line number Diff line number Diff line
@@ -230,8 +230,10 @@ fn build_commands() -> HashMap<String, CommandOption> {
        String::from("socket"),
        CommandOption {
            rules: vec![
                String::from("socket listen <auth-required>"),
                String::from("socket connect <address> <l2cap|rfcomm> <psm|uuid> <auth-required>"),
                String::from("socket listen <auth-required> <Bredr|LE>"),
                String::from(
                    "socket connect <address> <l2cap|rfcomm> <psm|uuid> <auth-required> <Bredr|LE>",
                ),
                String::from("socket disconnect <socket_id>"),
                String::from("socket set-on-connect-schedule <send|resend|dump>"),
            ],
@@ -1388,15 +1390,30 @@ impl CommandHandler {
                let auth_required = String::from(get_arg(args, 1)?)
                    .parse::<bool>()
                    .or(Err("Failed to parse auth-required"))?;
                let is_le = match &get_arg(args, 2)?[..] {
                    "LE" => true,
                    "Bredr" => false,
                    _ => {
                        return Err("Failed to parse socket type".into());
                    }
                };

                let SocketResult { status, id } = {
                    let mut context_proxy = self.context.lock().unwrap();
                    let proxy = context_proxy.socket_manager_dbus.as_mut().unwrap();
                    if auth_required {
                        if is_le {
                            proxy.listen_using_l2cap_le_channel(callback_id)
                        } else {
                            proxy.listen_using_l2cap_channel(callback_id)
                        }
                    } else {
                        if is_le {
                            proxy.listen_using_insecure_l2cap_le_channel(callback_id)
                        } else {
                            proxy.listen_using_insecure_l2cap_channel(callback_id)
                        }
                    }
                };

                if status != BtStatus::Success {
@@ -1420,6 +1437,14 @@ impl CommandHandler {
                    .parse::<bool>()
                    .or(Err("Failed to parse auth-required"))?;

                let is_le = match &get_arg(args, 5)?[..] {
                    "LE" => true,
                    "Bredr" => false,
                    _ => {
                        return Err("Failed to parse socket type".into());
                    }
                };

                let SocketResult { status, id } = {
                    let mut context_proxy = self.context.lock().unwrap();
                    let proxy = context_proxy.socket_manager_dbus.as_mut().unwrap();
@@ -1437,11 +1462,19 @@ impl CommandHandler {
                            };

                            if auth_required {
                                if is_le {
                                    proxy.create_l2cap_le_channel(callback_id, device, psm)
                                } else {
                                    proxy.create_l2cap_channel(callback_id, device, psm)
                                }
                            } else {
                                if is_le {
                                    proxy.create_insecure_l2cap_le_channel(callback_id, device, psm)
                                } else {
                                    proxy.create_insecure_l2cap_channel(callback_id, device, psm)
                                }
                            }
                        }
                        "rfcomm" => {
                            let uuid = match UuidHelper::parse_string(psm_or_uuid.clone()) {
                                Some(uu) => uu,
+30 −0
Original line number Diff line number Diff line
@@ -1906,11 +1906,21 @@ impl IBluetoothSocketManager for BluetoothSocketManagerDBus {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingInsecureL2capLeChannel")]
    fn listen_using_insecure_l2cap_le_channel(&mut self, callback: CallbackId) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingL2capChannel")]
    fn listen_using_l2cap_channel(&mut self, callback: CallbackId) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingL2capLeChannel")]
    fn listen_using_l2cap_le_channel(&mut self, callback: CallbackId) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingInsecureRfcommWithServiceRecord")]
    fn listen_using_insecure_rfcomm_with_service_record(
        &mut self,
@@ -1941,6 +1951,16 @@ impl IBluetoothSocketManager for BluetoothSocketManagerDBus {
        dbus_generated!()
    }

    #[dbus_method("CreateInsecureL2capLeChannel")]
    fn create_insecure_l2cap_le_channel(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        psm: i32,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("CreateL2capChannel")]
    fn create_l2cap_channel(
        &mut self,
@@ -1951,6 +1971,16 @@ impl IBluetoothSocketManager for BluetoothSocketManagerDBus {
        dbus_generated!()
    }

    #[dbus_method("CreateL2capLeChannel")]
    fn create_l2cap_le_channel(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        psm: i32,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("CreateInsecureRfcommSocketToServiceRecord")]
    fn create_insecure_rfcomm_socket_to_service_record(
        &mut self,
+30 −0
Original line number Diff line number Diff line
@@ -704,11 +704,21 @@ impl IBluetoothSocketManager for IBluetoothSocketManagerDBus {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingInsecureL2capLeChannel")]
    fn listen_using_insecure_l2cap_le_channel(&mut self, callback: CallbackId) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingL2capChannel")]
    fn listen_using_l2cap_channel(&mut self, callback: CallbackId) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingL2capLeChannel")]
    fn listen_using_l2cap_le_channel(&mut self, callback: CallbackId) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingInsecureRfcommWithServiceRecord")]
    fn listen_using_insecure_rfcomm_with_service_record(
        &mut self,
@@ -739,6 +749,16 @@ impl IBluetoothSocketManager for IBluetoothSocketManagerDBus {
        dbus_generated!()
    }

    #[dbus_method("CreateInsecureL2capLeChannel")]
    fn create_insecure_l2cap_le_channel(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        psm: i32,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("CreateL2capChannel")]
    fn create_l2cap_channel(
        &mut self,
@@ -749,6 +769,16 @@ impl IBluetoothSocketManager for IBluetoothSocketManagerDBus {
        dbus_generated!()
    }

    #[dbus_method("CreateL2capLeChannel")]
    fn create_l2cap_le_channel(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        psm: i32,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("CreateInsecureRfcommSocketToServiceRecord")]
    fn create_insecure_rfcomm_socket_to_service_record(
        &mut self,
+87 −8
Original line number Diff line number Diff line
@@ -85,10 +85,13 @@ impl BluetoothServerSocket {
        }
    }

    fn make_l2cap_channel(flags: i32) -> Self {
    fn make_l2cap_channel(flags: i32, is_le: bool) -> Self {
        BluetoothServerSocket {
            id: 0,
            sock_type: SocketType::L2cap,
            sock_type: match is_le {
                true => SocketType::L2capLe,
                false => SocketType::L2cap,
            },
            flags: flags | socket::SOCK_FLAG_NO_SDP,
            psm: Some(DYNAMIC_PSM_NO_SDP),
            channel: None,
@@ -193,11 +196,14 @@ impl BluetoothSocket {
        }
    }

    fn make_l2cap_channel(flags: i32, device: BluetoothDevice, psm: i32) -> Self {
    fn make_l2cap_channel(flags: i32, device: BluetoothDevice, psm: i32, is_le: bool) -> Self {
        BluetoothSocket {
            id: 0,
            remote_device: device,
            sock_type: SocketType::L2cap,
            sock_type: match is_le {
                true => SocketType::L2capLe,
                false => SocketType::L2cap,
            },
            flags,
            fd: None,
            port: psm,
@@ -274,6 +280,9 @@ pub trait IBluetoothSocketManager {
    /// Create an insecure listening L2CAP socket. PSM is dynamically assigned.
    fn listen_using_insecure_l2cap_channel(&mut self, callback: CallbackId) -> SocketResult;

    /// Create an insecure listening L2CAP LE socket. PSM is dynamically assigned.
    fn listen_using_insecure_l2cap_le_channel(&mut self, callback: CallbackId) -> SocketResult;

    /// Create an insecure listening RFCOMM socket. Channel is dynamically assigned.
    fn listen_using_insecure_rfcomm_with_service_record(
        &mut self,
@@ -285,6 +294,9 @@ pub trait IBluetoothSocketManager {
    /// Create a secure listening L2CAP socket. PSM is dynamically assigned.
    fn listen_using_l2cap_channel(&mut self, callback: CallbackId) -> SocketResult;

    /// Create a secure listening L2CAP LE socket. PSM is dynamically assigned.
    fn listen_using_l2cap_le_channel(&mut self, callback: CallbackId) -> SocketResult;

    /// Create a secure listening RFCOMM socket. Channel is dynamically assigned.
    fn listen_using_rfcomm_with_service_record(
        &mut self,
@@ -301,6 +313,14 @@ pub trait IBluetoothSocketManager {
        psm: i32,
    ) -> SocketResult;

    /// Create an insecure L2CAP LE connection.
    fn create_insecure_l2cap_le_channel(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        psm: i32,
    ) -> SocketResult;

    /// Create an insecure RFCOMM connection.
    fn create_insecure_rfcomm_socket_to_service_record(
        &mut self,
@@ -317,6 +337,14 @@ pub trait IBluetoothSocketManager {
        psm: i32,
    ) -> SocketResult;

    /// Create a secure L2CAP LE connection.
    fn create_l2cap_le_channel(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        psm: i32,
    ) -> SocketResult;

    /// Create an insecure RFCOMM connection.
    fn create_rfcomm_socket_to_service_record(
        &mut self,
@@ -1099,7 +1127,16 @@ impl IBluetoothSocketManager for BluetoothSocketManager {
            return SocketResult::new(BtStatus::NotReady, INVALID_SOCKET_ID);
        }

        let socket_info = BluetoothServerSocket::make_l2cap_channel(socket::SOCK_FLAG_NONE);
        let socket_info = BluetoothServerSocket::make_l2cap_channel(socket::SOCK_FLAG_NONE, false);
        self.socket_listen(socket_info, callback)
    }

    fn listen_using_insecure_l2cap_le_channel(&mut self, callback: CallbackId) -> SocketResult {
        if self.callbacks.get_by_id(callback).is_none() {
            return SocketResult::new(BtStatus::NotReady, INVALID_SOCKET_ID);
        }

        let socket_info = BluetoothServerSocket::make_l2cap_channel(socket::SOCK_FLAG_NONE, true);
        self.socket_listen(socket_info, callback)
    }

@@ -1108,7 +1145,18 @@ impl IBluetoothSocketManager for BluetoothSocketManager {
            return SocketResult::new(BtStatus::NotReady, INVALID_SOCKET_ID);
        }

        let socket_info = BluetoothServerSocket::make_l2cap_channel(socket::SOCK_META_FLAG_SECURE);
        let socket_info =
            BluetoothServerSocket::make_l2cap_channel(socket::SOCK_META_FLAG_SECURE, false);
        self.socket_listen(socket_info, callback)
    }

    fn listen_using_l2cap_le_channel(&mut self, callback: CallbackId) -> SocketResult {
        if self.callbacks.get_by_id(callback).is_none() {
            return SocketResult::new(BtStatus::NotReady, INVALID_SOCKET_ID);
        }

        let socket_info =
            BluetoothServerSocket::make_l2cap_channel(socket::SOCK_META_FLAG_SECURE, true);
        self.socket_listen(socket_info, callback)
    }

@@ -1153,7 +1201,23 @@ impl IBluetoothSocketManager for BluetoothSocketManager {
            return SocketResult::new(BtStatus::NotReady, INVALID_SOCKET_ID);
        }

        let socket_info = BluetoothSocket::make_l2cap_channel(socket::SOCK_FLAG_NONE, device, psm);
        let socket_info =
            BluetoothSocket::make_l2cap_channel(socket::SOCK_FLAG_NONE, device, psm, false);
        self.socket_connect(socket_info, callback)
    }

    fn create_insecure_l2cap_le_channel(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        psm: i32,
    ) -> SocketResult {
        if self.callbacks.get_by_id(callback).is_none() {
            return SocketResult::new(BtStatus::NotReady, INVALID_SOCKET_ID);
        }

        let socket_info =
            BluetoothSocket::make_l2cap_channel(socket::SOCK_FLAG_NONE, device, psm, true);
        self.socket_connect(socket_info, callback)
    }

@@ -1168,7 +1232,22 @@ impl IBluetoothSocketManager for BluetoothSocketManager {
        }

        let socket_info =
            BluetoothSocket::make_l2cap_channel(socket::SOCK_META_FLAG_SECURE, device, psm);
            BluetoothSocket::make_l2cap_channel(socket::SOCK_META_FLAG_SECURE, device, psm, false);
        self.socket_connect(socket_info, callback)
    }

    fn create_l2cap_le_channel(
        &mut self,
        callback: CallbackId,
        device: BluetoothDevice,
        psm: i32,
    ) -> SocketResult {
        if self.callbacks.get_by_id(callback).is_none() {
            return SocketResult::new(BtStatus::NotReady, INVALID_SOCKET_ID);
        }

        let socket_info =
            BluetoothSocket::make_l2cap_channel(socket::SOCK_META_FLAG_SECURE, device, psm, true);
        self.socket_connect(socket_info, callback)
    }