diff --git a/adb_client/src/models/adb_server_command.rs b/adb_client/src/models/adb_server_command.rs index 23ed7d8..be72674 100644 --- a/adb_client/src/models/adb_server_command.rs +++ b/adb_client/src/models/adb_server_command.rs @@ -22,6 +22,8 @@ pub(crate) enum AdbServerCommand { FrameBuffer, Sync, Reboot(RebootType), + Forward(String, String, String), + Reverse(String, String), } impl Display for AdbServerCommand { @@ -53,6 +55,12 @@ impl Display for AdbServerCommand { write!(f, "host:pair:{code}:{addr}") } AdbServerCommand::FrameBuffer => write!(f, "framebuffer:"), + AdbServerCommand::Forward(serial, remote, local) => { + write!(f, "host-serial:{serial}:forward:{local};{remote}") + } + AdbServerCommand::Reverse(remote, local) => { + write!(f, "reverse:forward:{remote};{local}") + } } } } diff --git a/adb_client/src/server/device_commands/forward.rs b/adb_client/src/server/device_commands/forward.rs new file mode 100644 index 0000000..ab9e90c --- /dev/null +++ b/adb_client/src/server/device_commands/forward.rs @@ -0,0 +1,14 @@ +use crate::{models::AdbServerCommand, ADBServerDevice, Result}; + +impl ADBServerDevice { + /// Forward socket connection + pub fn forward(&mut self, remote: String, local: String) -> Result<()> { + let serial = self.identifier.clone(); + self.connect()? + .send_adb_request(AdbServerCommand::TransportSerial(serial.clone()))?; + + self.get_transport_mut() + .proxy_connection(AdbServerCommand::Forward(serial, remote, local), false) + .map(|_| ()) + } +} diff --git a/adb_client/src/server/device_commands/mod.rs b/adb_client/src/server/device_commands/mod.rs index c4e4f8a..ea6bae4 100644 --- a/adb_client/src/server/device_commands/mod.rs +++ b/adb_client/src/server/device_commands/mod.rs @@ -1,9 +1,11 @@ +mod forward; mod framebuffer; mod host_features; mod list; mod logcat; mod reboot; mod recv; +mod reverse; mod send; mod stat; mod transport; diff --git a/adb_client/src/server/device_commands/reverse.rs b/adb_client/src/server/device_commands/reverse.rs new file mode 100644 index 0000000..2062653 --- /dev/null +++ b/adb_client/src/server/device_commands/reverse.rs @@ -0,0 +1,14 @@ +use crate::{models::AdbServerCommand, ADBServerDevice, Result}; + +impl ADBServerDevice { + /// Reverse socket connection + pub fn reverse(&mut self, remote: String, local: String) -> Result<()> { + let serial = self.identifier.clone(); + self.connect()? + .send_adb_request(AdbServerCommand::TransportSerial(serial))?; + + self.get_transport_mut() + .proxy_connection(AdbServerCommand::Reverse(remote, local), false) + .map(|_| ()) + } +}