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

Commit a38c0063 authored by Jesse Melhuish's avatar Jesse Melhuish
Browse files

Floss: Add more flexible RFCOMM listen method

Bug: 233123814
Tag: #floss
Test: manual
Change-Id: I71308c12097f1bb84263ec30eb66efb96b9bb387
parent da82ba8b
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -1931,6 +1931,18 @@ impl IBluetoothSocketManager for BluetoothSocketManagerDBus {
        dbus_generated!()
        dbus_generated!()
    }
    }


    #[dbus_method("ListenUsingRfcomm")]
    fn listen_using_rfcomm(
        &mut self,
        callback: CallbackId,
        channel: Option<i32>,
        application_uuid: Option<Uuid>,
        name: Option<String>,
        flags: Option<i32>,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("CreateInsecureL2capChannel")]
    #[dbus_method("CreateInsecureL2capChannel")]
    fn create_insecure_l2cap_channel(
    fn create_insecure_l2cap_channel(
        &mut self,
        &mut self,
+12 −0
Original line number Original line Diff line number Diff line
@@ -719,6 +719,18 @@ impl IBluetoothSocketManager for IBluetoothSocketManagerDBus {
        dbus_generated!()
        dbus_generated!()
    }
    }


    #[dbus_method("ListenUsingRfcomm")]
    fn listen_using_rfcomm(
        &mut self,
        callback: CallbackId,
        channel: Option<i32>,
        application_uuid: Option<Uuid>,
        name: Option<String>,
        flags: Option<i32>,
    ) -> SocketResult {
        dbus_generated!()
    }

    #[dbus_method("ListenUsingRfcommWithServiceRecord")]
    #[dbus_method("ListenUsingRfcommWithServiceRecord")]
    fn listen_using_rfcomm_with_service_record(
    fn listen_using_rfcomm_with_service_record(
        &mut self,
        &mut self,
+59 −4
Original line number Original line Diff line number Diff line
@@ -97,7 +97,24 @@ impl BluetoothServerSocket {
        }
        }
    }
    }


    fn make_rfcomm_channel(flags: i32, name: String, uuid: Uuid) -> Self {
    fn make_rfcomm_channel(
        flags: i32,
        name: Option<String>,
        channel: Option<i32>,
        uuid: Option<Uuid>,
    ) -> Self {
        BluetoothServerSocket {
            id: 0,
            sock_type: SocketType::Rfcomm,
            flags,
            psm: None,
            channel: channel,
            name: name,
            uuid: uuid,
        }
    }

    fn make_default_rfcomm_channel(flags: i32, name: String, uuid: Uuid) -> Self {
        BluetoothServerSocket {
        BluetoothServerSocket {
            id: 0,
            id: 0,
            sock_type: SocketType::Rfcomm,
            sock_type: SocketType::Rfcomm,
@@ -293,6 +310,18 @@ pub trait IBluetoothSocketManager {
        uuid: Uuid,
        uuid: Uuid,
    ) -> SocketResult;
    ) -> SocketResult;


    /// Generic method for setting up an RFCOMM listening socket.  Prefer to use one of the other
    /// RFCOMM listen methods when possible as they reflect the more preferred RFCOMM flows, but
    /// this method exposes all of the options that the stack supports.
    fn listen_using_rfcomm(
        &mut self,
        callback: CallbackId,
        channel: Option<i32>,
        application_uuid: Option<Uuid>,
        name: Option<String>,
        flags: Option<i32>,
    ) -> SocketResult;

    /// Create an insecure L2CAP connection.
    /// Create an insecure L2CAP connection.
    fn create_insecure_l2cap_channel(
    fn create_insecure_l2cap_channel(
        &mut self,
        &mut self,
@@ -1123,7 +1152,7 @@ impl IBluetoothSocketManager for BluetoothSocketManager {
        }
        }


        let socket_info =
        let socket_info =
            BluetoothServerSocket::make_rfcomm_channel(socket::SOCK_FLAG_NONE, name, uuid);
            BluetoothServerSocket::make_default_rfcomm_channel(socket::SOCK_FLAG_NONE, name, uuid);
        self.socket_listen(socket_info, callback)
        self.socket_listen(socket_info, callback)
    }
    }


@@ -1137,12 +1166,38 @@ impl IBluetoothSocketManager for BluetoothSocketManager {
            return SocketResult::new(BtStatus::NotReady, INVALID_SOCKET_ID);
            return SocketResult::new(BtStatus::NotReady, INVALID_SOCKET_ID);
        }
        }


        let socket_info =
        let socket_info = BluetoothServerSocket::make_default_rfcomm_channel(
            BluetoothServerSocket::make_rfcomm_channel(socket::SOCK_META_FLAG_SECURE, name, uuid);
            socket::SOCK_META_FLAG_SECURE,
            name,
            uuid,
        );


        self.socket_listen(socket_info, callback)
        self.socket_listen(socket_info, callback)
    }
    }


    fn listen_using_rfcomm(
        &mut self,
        callback: CallbackId,
        channel: Option<i32>,
        application_uuid: Option<Uuid>,
        name: Option<String>,
        flags: Option<i32>,
    ) -> SocketResult {
        if self.callbacks.get_by_id(callback).is_none() {
            return SocketResult::new(BtStatus::NotReady, INVALID_SOCKET_ID);
        }

        let flags = match flags {
            Some(flags) => flags,
            None => socket::SOCK_FLAG_NONE,
        };

        self.socket_listen(
            BluetoothServerSocket::make_rfcomm_channel(flags, name, channel, application_uuid),
            callback,
        )
    }

    fn create_insecure_l2cap_channel(
    fn create_insecure_l2cap_channel(
        &mut self,
        &mut self,
        callback: CallbackId,
        callback: CallbackId,