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

Commit 0c762adc authored by Hsin-chen Chuang's avatar Hsin-chen Chuang
Browse files

floss: btclient: Add listen-rfcomm and send-msc commands

Bug: 278505039
Tag: #floss
Test: RFCOMM/DEVA-DEVB/RFC/BV-21-C RFCOMM/DEVA-DEVB/RFC/BV-22-C
Change-Id: I5983b47aaa8871f0ff2957544c5ada2f987aeb2b
parent 17790ae5
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -246,6 +246,8 @@ fn build_commands() -> HashMap<String, CommandOption> {
        CommandOption {
            rules: vec![
                String::from("socket listen <auth-required> <Bredr|LE>"),
                String::from("socket listen-rfcomm <scn>"),
                String::from("socket send-msc <dlci> <address>"),
                String::from(
                    "socket connect <address> <l2cap|rfcomm> <psm|uuid> <auth-required> <Bredr|LE>",
                ),
@@ -1461,6 +1463,33 @@ impl CommandHandler {

                self.context.lock().unwrap().socket_test_schedule = Some(schedule);
            }
            "send-msc" => {
                let dlci =
                    String::from(get_arg(args, 1)?).parse::<u8>().or(Err("Failed parsing DLCI"))?;
                let addr = String::from(get_arg(args, 2)?);
                self.context.lock().unwrap().qa_dbus.as_mut().unwrap().rfcomm_send_msc(dlci, addr);
            }
            "listen-rfcomm" => {
                let scn = String::from(get_arg(args, 1)?)
                    .parse::<i32>()
                    .or(Err("Failed parsing Service Channel Number"))?;
                let SocketResult { status, id } = self
                    .context
                    .lock()
                    .unwrap()
                    .socket_manager_dbus
                    .as_mut()
                    .unwrap()
                    .listen_using_rfcomm(callback_id, Some(scn), None, None, None);
                if status != BtStatus::Success {
                    return Err(format!(
                        "Failed to request for listening using rfcomm, status = {:?}",
                        status,
                    )
                    .into());
                }
                print_info!("Requested for listening using rfcomm on socket {}", id);
            }
            "listen" => {
                let auth_required = String::from(get_arg(args, 1)?)
                    .parse::<bool>()
+4 −0
Original line number Diff line number Diff line
@@ -2269,4 +2269,8 @@ impl IBluetoothQA for BluetoothQADBus {
    fn add_media_player(&self, name: String, browsing_supported: bool) {
        dbus_generated!()
    }
    #[dbus_method("RfcommSendMsc")]
    fn rfcomm_send_msc(&self, dlci: u8, addr: String) {
        dbus_generated!()
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -13,4 +13,8 @@ impl IBluetoothQA for IBluetoothQADBus {
    fn add_media_player(&self, name: String, browsing_supported: bool) {
        dbus_generated!()
    }
    #[dbus_method("RfcommSendMsc")]
    fn rfcomm_send_msc(&self, dlci: u8, addr: String) {
        dbus_generated!()
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ use tokio::sync::mpsc::Sender;
/// Defines the Qualification API
pub trait IBluetoothQA {
    fn add_media_player(&self, name: String, browsing_supported: bool);
    fn rfcomm_send_msc(&self, dlci: u8, addr: String);
}

pub struct BluetoothQA {
@@ -25,4 +26,10 @@ impl IBluetoothQA for BluetoothQA {
            let _ = txl.send(Message::QaAddMediaPlayer(name, browsing_supported)).await;
        });
    }
    fn rfcomm_send_msc(&self, dlci: u8, addr: String) {
        let txl = self.tx.clone();
        tokio::spawn(async move {
            let _ = txl.send(Message::QaRfcommSendMsc(dlci, addr)).await;
        });
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -127,6 +127,7 @@ pub enum Message {

    // Qualification Only
    QaAddMediaPlayer(String, bool),
    QaRfcommSendMsc(u8, String),
}

/// Represents suspend mode of a module.
@@ -353,6 +354,9 @@ impl Stack {
                Message::QaAddMediaPlayer(name, browsing_supported) => {
                    bluetooth_media.lock().unwrap().add_player(name, browsing_supported);
                }
                Message::QaRfcommSendMsc(dlci, addr) => {
                    bluetooth_socketmgr.lock().unwrap().rfcomm_send_msc(dlci, addr);
                }
            }
        }
    }
Loading