-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 52c715f
Showing
6 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"files.associations": { | ||
"fcntl.h": "c" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
|
||
} |