Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperq committed Nov 8, 2023
0 parents commit 52c715f
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"fcntl.h": "c"
}
}
40 changes: 40 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "diag"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
libc = "0.2.150"
nix = { version = "0.27.1", features = ["ioctl"]}

2 changes: 2 additions & 0 deletions make.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cross rustc --target armv7-unknown-linux-gnueabihf -- -C target-feature=+crt-static
adb push target/armv7-unknown-linux-gnueabihf/debug/diag /tmp/diag
53 changes: 53 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use std::fs::File;
use std::mem;
use std::os::unix::io::AsRawFd;

fn main() {
const DIAG_IOCTL_SWITCH_LOGGING: u32 = 7;
const MEMORY_DEVICE_MODE: i32 = 2;
const DIAG_IOCTL_REMOTE_DEV: u32 = 32;

let mut mode_param: [i32; 3] = [MEMORY_DEVICE_MODE, -1, 0]; // diag_logging_mode_param_t
let use_mdm: i32 = 0;

let diag_fd: i32;

println!("Initializing DIAG");

let diag_result = File::options().read(true).write(true).open("/dev/diag");
match &diag_result {
Ok(file) => {
diag_fd = file.as_raw_fd();
}
Err(_) => {
println!("error opening diag device.");
std::process::exit(1);
}
}


unsafe {
if libc::ioctl(diag_fd, DIAG_IOCTL_SWITCH_LOGGING, MEMORY_DEVICE_MODE, 0, 0, 0) < 0
&& libc::ioctl(
diag_fd,
DIAG_IOCTL_SWITCH_LOGGING,
&mut mode_param as *mut _,
mem::size_of::<[i32; 3]>(), 0, 0, 0, 0
) < 0
{
println!("ioctl failed 1");
//std::process::exit(1);
}
}


unsafe {
if libc::ioctl(diag_fd, DIAG_IOCTL_REMOTE_DEV, &use_mdm as *const i32) < 0 {
println!("ioctl failed 2");
std::process::exit(1);
}
}

println!("successfully opened diag device");

}

0 comments on commit 52c715f

Please sign in to comment.