diff --git a/Cargo.toml b/Cargo.toml index cd93570..71caa82 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sim_card_batcher" -version = "0.1.0" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index f245e76..77c5d5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 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"))] 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 you want to execute the "deactivate5g" script - #[arg(long = "deactivate-5g", default_value_t = false)] - deactivate5g: bool, + /// Set true if IMS is used + #[arg(long = "ims", default_value_t = false)] + ims: 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,8 +55,6 @@ 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 { @@ -66,7 +64,7 @@ fn main() { // calculate the new IMSI 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()); print!("{}", args.bin); @@ -88,9 +86,7 @@ fn main() { // execute pySim and wait for it to stop let output = command.output().expect("process failed to execute!"); if output.status.success() { - let output_string = String::from_utf8(output.stdout).unwrap(); - pysim_outputs.push(output_string.clone()); - println!("{} ", output_string); + println!("{} ", String::from_utf8(output.stdout).unwrap()); println!("{} programmed sim card", "SUCCESSFULLY".green()); } else { 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 /* @@ -123,7 +108,7 @@ fn main() { * c = op is opc * 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), args.ki, "8000", @@ -144,57 +129,25 @@ fn main() { } }, "0" - )); + ); - /* - * 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" - )); + 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); } // 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); } @@ -205,9 +158,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 => { - 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), - }; + } } diff --git a/src/parser.rs b/src/parser.rs index d9a8ee9..c424855 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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.to_string(), + imsi, 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.to_string(), + imsi, 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, Box> { 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