Compare commits
2 Commits
a7bbbe95cc
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6288bd5f3f | ||
|
|
93fcdbeca6 |
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "sim_card_batcher"
|
||||||
|
version = "0.2.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
csv = "1.1"
|
||||||
|
serde = { version = "1.0.152", features = ["derive"] }
|
||||||
|
clap = { version = "4.0", features = ["derive"] }
|
||||||
|
colored = "2"
|
||||||
79
src/main.rs
79
src/main.rs
@ -21,7 +21,7 @@ pub struct CliArgs {
|
|||||||
/// The path to the csv file to read
|
/// The path to the csv file to read
|
||||||
#[arg(short = 'c', long = "csv")]
|
#[arg(short = 'c', long = "csv")]
|
||||||
csv: String,
|
csv: String,
|
||||||
/// Set the output file with the commands for the core
|
/// Set the output file with the commands for the HSS on the core
|
||||||
#[arg(short = 'o', long = "output", default_value_t = String::from("output"))]
|
#[arg(short = 'o', long = "output", default_value_t = String::from("output"))]
|
||||||
output_file: String,
|
output_file: String,
|
||||||
/// The name of the nework
|
/// The name of the nework
|
||||||
@ -44,9 +44,9 @@ pub struct CliArgs {
|
|||||||
use_op: bool,
|
use_op: bool,
|
||||||
#[arg(long = "op", default_value_t = String::from("00000000000000000000000000000000"))]
|
#[arg(long = "op", default_value_t = String::from("00000000000000000000000000000000"))]
|
||||||
op: String,
|
op: String,
|
||||||
/// Set true if you want to execute the "deactivate5g" script
|
/// Set true if IMS is used
|
||||||
#[arg(long = "deactivate-5g", default_value_t = false)]
|
#[arg(long = "ims", default_value_t = false)]
|
||||||
deactivate5g: bool,
|
ims: bool,
|
||||||
/// Set true to only do a dry run (print commands and not execute them)
|
/// Set true to only do a dry run (print commands and not execute them)
|
||||||
#[arg(long = "dry-run", default_value_t = false)]
|
#[arg(long = "dry-run", default_value_t = false)]
|
||||||
dry_run: bool,
|
dry_run: bool,
|
||||||
@ -55,8 +55,6 @@ pub struct CliArgs {
|
|||||||
fn main() {
|
fn main() {
|
||||||
let args = CliArgs::parse();
|
let args = CliArgs::parse();
|
||||||
let mut user_provision_commands = vec![];
|
let mut user_provision_commands = vec![];
|
||||||
let mut provision_commands = vec![];
|
|
||||||
let mut pysim_outputs = vec![];
|
|
||||||
// parse the supplied card configs
|
// parse the supplied card configs
|
||||||
let card_configs = parser::parse_csv(&args.csv).unwrap();
|
let card_configs = parser::parse_csv(&args.csv).unwrap();
|
||||||
for mut conf in card_configs {
|
for mut conf in card_configs {
|
||||||
@ -66,7 +64,7 @@ fn main() {
|
|||||||
// calculate the new IMSI
|
// calculate the new IMSI
|
||||||
parser::update_imsi(&mut conf, &args);
|
parser::update_imsi(&mut conf, &args);
|
||||||
|
|
||||||
let pysim_args = parser::generate_pysim_args(&mut conf, &args);
|
let pysim_args = parser::generate_pysim_args(&conf, &args);
|
||||||
|
|
||||||
println!("\n{}:", "EXECUTING".red());
|
println!("\n{}:", "EXECUTING".red());
|
||||||
print!("{}", args.bin);
|
print!("{}", args.bin);
|
||||||
@ -88,9 +86,7 @@ fn main() {
|
|||||||
// execute pySim and wait for it to stop
|
// execute pySim and wait for it to stop
|
||||||
let output = command.output().expect("process failed to execute!");
|
let output = command.output().expect("process failed to execute!");
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
let output_string = String::from_utf8(output.stdout).unwrap();
|
println!("{} ", String::from_utf8(output.stdout).unwrap());
|
||||||
pysim_outputs.push(output_string.clone());
|
|
||||||
println!("{} ", output_string);
|
|
||||||
println!("{} programmed sim card", "SUCCESSFULLY".green());
|
println!("{} programmed sim card", "SUCCESSFULLY".green());
|
||||||
} else {
|
} else {
|
||||||
println!("{} ", String::from_utf8(output.stdout).unwrap());
|
println!("{} ", String::from_utf8(output.stdout).unwrap());
|
||||||
@ -100,17 +96,6 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// possibly execute deactivate5g command
|
|
||||||
if args.deactivate5g {
|
|
||||||
println!("{}: ./pySim-shell.py -p{} --script scripts/deactivate-5g.script", "EXECUTING".red(), &args.device);
|
|
||||||
if args.dry_run {
|
|
||||||
print!("{}: The command is not executed since {} is enabled\n", "WARNING".yellow(), "dry_run".yellow());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//TODO: Implement me
|
|
||||||
println!("{}. Not Implemented Yet!", "TODO".red());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// add command to be run on the open5gcore
|
// add command to be run on the open5gcore
|
||||||
/*
|
/*
|
||||||
@ -123,7 +108,7 @@ fn main() {
|
|||||||
* c = op is opc
|
* c = op is opc
|
||||||
* u = usim_type (= 0)
|
* u = usim_type (= 0)
|
||||||
*/
|
*/
|
||||||
user_provision_commands.push(format!("./provision_user.sh -S {} -k {} -a {} -o {} -s {} -t {} -c {} -u {}",
|
let mut user_provision_command = format!("./provision_user.sh -S {} -k {} -a {} -o {} -s {} -t {} -c {} -u {}",
|
||||||
String::from(&conf.IMSI),
|
String::from(&conf.IMSI),
|
||||||
args.ki,
|
args.ki,
|
||||||
"8000",
|
"8000",
|
||||||
@ -144,57 +129,25 @@ fn main() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"0"
|
"0"
|
||||||
));
|
);
|
||||||
|
|
||||||
/*
|
if args.ims {
|
||||||
* I = imsi
|
user_provision_command.push_str(&format!(" -n mnc{}.mcc{}.3gppnetwork.org -T 49{}", args.mnc, args.mcc, imsi_ending));
|
||||||
* M = msisdn
|
|
||||||
* n = default
|
|
||||||
* u = username, leer lassen -> imsi
|
|
||||||
* k = Ki
|
|
||||||
* o = opc/op
|
|
||||||
* s = sqn wie oben (= 0)
|
|
||||||
* v = yes
|
|
||||||
* a = 8000 amf
|
|
||||||
*/
|
|
||||||
provision_commands.push(format!("./provision.sh -I {} -M {} -n mnc{}.mcc{}.3gppnetwork.org -k {} -o {} -s {} -v {} -a {}",
|
|
||||||
conf.IMSI,
|
|
||||||
format!("49{}", imsi_ending),
|
|
||||||
args.mnc,
|
|
||||||
args.mcc,
|
|
||||||
args.ki,
|
|
||||||
{
|
|
||||||
if args.use_op {
|
|
||||||
&args.op
|
|
||||||
} else {
|
|
||||||
&args.opc
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"0",
|
user_provision_commands.push(user_provision_command);
|
||||||
"yes",
|
|
||||||
"8000"
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// output to file
|
// output to file
|
||||||
let mut file = File::create(args.output_file).unwrap();
|
let mut file = File::create(args.output_file).unwrap();
|
||||||
writeln!(&mut file, "PySim outputs:").unwrap();
|
|
||||||
for pysim_out in pysim_outputs {
|
|
||||||
writeln!(&mut file, "{}", pysim_out).unwrap();
|
|
||||||
}
|
|
||||||
writeln!(&mut file, "\nCommands to be executed on core\nUDM provisioning:").unwrap();
|
|
||||||
for command in user_provision_commands {
|
for command in user_provision_commands {
|
||||||
writeln!(&mut file, "{}", command).unwrap();
|
writeln!(&mut file, "{}", command).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
writeln!(&mut file, "\nHSS provisioning:").unwrap();
|
|
||||||
for command in provision_commands {
|
|
||||||
writeln!(&mut file, "{}", command).unwrap();
|
|
||||||
}
|
|
||||||
exit_programm(0)
|
exit_programm(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exit_programm(code: i32) -> () {
|
fn exit_programm(code: i32) {
|
||||||
println!("{}", "GOODBYE!".green());
|
println!("{}", "GOODBYE!".green());
|
||||||
exit(code);
|
exit(code);
|
||||||
}
|
}
|
||||||
@ -205,9 +158,9 @@ fn wait_for_user(msg: &str) -> bool {
|
|||||||
let mut next_string = String::new();
|
let mut next_string = String::new();
|
||||||
match std::io::stdin().read_line(&mut next_string) {
|
match std::io::stdin().read_line(&mut next_string) {
|
||||||
Ok(n) if n > 0 => {
|
Ok(n) if n > 0 => {
|
||||||
return 'a' != next_string.chars().next().unwrap()
|
!next_string.starts_with('a')
|
||||||
}
|
}
|
||||||
Ok(_) => return true, // other input is ignored
|
Ok(_) => true, // other input is ignored
|
||||||
Err(err) => panic!("{}", err),
|
Err(err) => panic!("{}", err),
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,7 +61,7 @@ pub fn generate_pysim_args(card_config: &CardValues, cli_args: &CliArgs) -> Vec<
|
|||||||
let op = format!("--op={}", cli_args.op);
|
let op = format!("--op={}", cli_args.op);
|
||||||
vec![
|
vec![
|
||||||
p,
|
p,
|
||||||
imsi.to_string(),
|
imsi,
|
||||||
name,
|
name,
|
||||||
mnc,
|
mnc,
|
||||||
mcc,
|
mcc,
|
||||||
@ -74,7 +74,7 @@ pub fn generate_pysim_args(card_config: &CardValues, cli_args: &CliArgs) -> Vec<
|
|||||||
let opc = format!("--opc={}", cli_args.opc);
|
let opc = format!("--opc={}", cli_args.opc);
|
||||||
vec![
|
vec![
|
||||||
p,
|
p,
|
||||||
imsi.to_string(),
|
imsi,
|
||||||
name,
|
name,
|
||||||
mnc,
|
mnc,
|
||||||
mcc,
|
mcc,
|
||||||
@ -89,16 +89,16 @@ pub fn generate_pysim_args(card_config: &CardValues, cli_args: &CliArgs) -> Vec<
|
|||||||
pub fn parse_csv(path: &str) -> Result<Vec<CardValues>, Box<dyn Error>> {
|
pub fn parse_csv(path: &str) -> Result<Vec<CardValues>, Box<dyn Error>> {
|
||||||
if let Ok(mut lines) = read_lines(path) {
|
if let Ok(mut lines) = read_lines(path) {
|
||||||
let first_line = &lines.next().unwrap().unwrap();
|
let first_line = &lines.next().unwrap().unwrap();
|
||||||
let first_line = first_line.replace(" ", "");
|
let first_line = first_line.replace(' ', "");
|
||||||
//split the first line into a vec
|
//split the first line into a vec
|
||||||
let first_line: Vec<&str> = first_line.split(",").collect();
|
let first_line: Vec<&str> = first_line.split(',').collect();
|
||||||
let header = StringRecord::from(first_line);
|
let header = StringRecord::from(first_line);
|
||||||
// now we got the header. Continue to deserialize every other line
|
// now we got the header. Continue to deserialize every other line
|
||||||
Ok(lines.map(|line| {
|
Ok(lines.map(|line| {
|
||||||
// unpack line
|
// unpack line
|
||||||
let line = line.unwrap();
|
let line = line.unwrap();
|
||||||
let line = line.replace(" ", "");
|
let line = line.replace(' ', "");
|
||||||
let line: Vec<&str> = line.split(",").collect();
|
let line: Vec<&str> = line.split(',').collect();
|
||||||
let record = StringRecord::from(line);
|
let record = StringRecord::from(line);
|
||||||
let sim_conf: CardValues = record.deserialize(Some(&header)).unwrap();
|
let sim_conf: CardValues = record.deserialize(Some(&header)).unwrap();
|
||||||
sim_conf
|
sim_conf
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user