Compare commits

..

No commits in common. "master" and "a7bbbe95ccea8e12b2dc1ab7d1d41ef6a44f0bbc" have entirely different histories.

3 changed files with 70 additions and 35 deletions

View File

@ -1,12 +0,0 @@
[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"

View File

@ -21,7 +21,7 @@ pub struct CliArgs {
/// The path to the csv file to read
#[arg(short = 'c', long = "csv")]
csv: String,
/// Set the output file with the commands for the HSS on the core
/// Set the output file with the commands for the core
#[arg(short = 'o', long = "output", default_value_t = String::from("output"))]
output_file: String,
/// The name of the nework
@ -44,9 +44,9 @@ pub struct CliArgs {
use_op: bool,
#[arg(long = "op", default_value_t = String::from("00000000000000000000000000000000"))]
op: String,
/// Set true if IMS is used
#[arg(long = "ims", default_value_t = false)]
ims: bool,
/// Set true if you want to execute the "deactivate5g" script
#[arg(long = "deactivate-5g", default_value_t = false)]
deactivate5g: bool,
/// Set true to only do a dry run (print commands and not execute them)
#[arg(long = "dry-run", default_value_t = false)]
dry_run: bool,
@ -55,6 +55,8 @@ pub struct CliArgs {
fn main() {
let args = CliArgs::parse();
let mut user_provision_commands = vec![];
let mut provision_commands = vec![];
let mut pysim_outputs = vec![];
// parse the supplied card configs
let card_configs = parser::parse_csv(&args.csv).unwrap();
for mut conf in card_configs {
@ -64,7 +66,7 @@ fn main() {
// calculate the new IMSI
parser::update_imsi(&mut conf, &args);
let pysim_args = parser::generate_pysim_args(&conf, &args);
let pysim_args = parser::generate_pysim_args(&mut conf, &args);
println!("\n{}:", "EXECUTING".red());
print!("{}", args.bin);
@ -86,7 +88,9 @@ fn main() {
// execute pySim and wait for it to stop
let output = command.output().expect("process failed to execute!");
if output.status.success() {
println!("{} ", String::from_utf8(output.stdout).unwrap());
let output_string = String::from_utf8(output.stdout).unwrap();
pysim_outputs.push(output_string.clone());
println!("{} ", output_string);
println!("{} programmed sim card", "SUCCESSFULLY".green());
} else {
println!("{} ", String::from_utf8(output.stdout).unwrap());
@ -96,6 +100,17 @@ 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
/*
@ -108,7 +123,7 @@ fn main() {
* c = op is opc
* u = usim_type (= 0)
*/
let mut user_provision_command = format!("./provision_user.sh -S {} -k {} -a {} -o {} -s {} -t {} -c {} -u {}",
user_provision_commands.push(format!("./provision_user.sh -S {} -k {} -a {} -o {} -s {} -t {} -c {} -u {}",
String::from(&conf.IMSI),
args.ki,
"8000",
@ -129,25 +144,57 @@ fn main() {
}
},
"0"
);
));
if args.ims {
user_provision_command.push_str(&format!(" -n mnc{}.mcc{}.3gppnetwork.org -T 49{}", args.mnc, args.mcc, imsi_ending));
}
user_provision_commands.push(user_provision_command);
/*
* I = imsi
* 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",
"yes",
"8000"
));
}
// output to file
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 {
writeln!(&mut file, "{}", command).unwrap();
}
writeln!(&mut file, "\nHSS provisioning:").unwrap();
for command in provision_commands {
writeln!(&mut file, "{}", command).unwrap();
}
exit_programm(0)
}
fn exit_programm(code: i32) {
fn exit_programm(code: i32) -> () {
println!("{}", "GOODBYE!".green());
exit(code);
}
@ -158,9 +205,9 @@ fn wait_for_user(msg: &str) -> bool {
let mut next_string = String::new();
match std::io::stdin().read_line(&mut next_string) {
Ok(n) if n > 0 => {
!next_string.starts_with('a')
return 'a' != next_string.chars().next().unwrap()
}
Ok(_) => true, // other input is ignored
Ok(_) => return true, // other input is ignored
Err(err) => panic!("{}", err),
}
};
}

View File

@ -61,7 +61,7 @@ pub fn generate_pysim_args(card_config: &CardValues, cli_args: &CliArgs) -> Vec<
let op = format!("--op={}", cli_args.op);
vec![
p,
imsi,
imsi.to_string(),
name,
mnc,
mcc,
@ -74,7 +74,7 @@ pub fn generate_pysim_args(card_config: &CardValues, cli_args: &CliArgs) -> Vec<
let opc = format!("--opc={}", cli_args.opc);
vec![
p,
imsi,
imsi.to_string(),
name,
mnc,
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>> {
if let Ok(mut lines) = read_lines(path) {
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
let first_line: Vec<&str> = first_line.split(',').collect();
let first_line: Vec<&str> = first_line.split(",").collect();
let header = StringRecord::from(first_line);
// now we got the header. Continue to deserialize every other line
Ok(lines.map(|line| {
// unpack line
let line = line.unwrap();
let line = line.replace(' ', "");
let line: Vec<&str> = line.split(',').collect();
let line = line.replace(" ", "");
let line: Vec<&str> = line.split(",").collect();
let record = StringRecord::from(line);
let sim_conf: CardValues = record.deserialize(Some(&header)).unwrap();
sim_conf