From 1a08d11b091c259ed2cc5b39503102a7d3b5c3c6 Mon Sep 17 00:00:00 2001 From: Julius Herrmann Date: Thu, 22 Jun 2023 20:54:28 +0200 Subject: [PATCH] update to rel 7.4 of OpenCore --- .gitignore | 2 ++ Cargo.toml | 2 +- src/main.rs | 73 ++++++++++++++++++++++++-------------------- src/parser.rs | 83 +++++++++++++++++++++------------------------------ 4 files changed, 78 insertions(+), 82 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..501aa2a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +SIM_config.csv diff --git a/Cargo.toml b/Cargo.toml index 71caa82..90017ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sim_card_batcher" -version = "0.2.0" +version = "0.3.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 77c5d5a..b8d9bc4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,11 @@ -use std::fs::File; -use std::io::prelude::*; -use std::process::{Command, exit}; use clap::Parser; use colored::*; - +use std::fs::File; +use std::io::prelude::*; +use std::process::{exit, Command}; mod parser; - // setup cli parser #[derive(Parser, Debug)] #[command( @@ -21,7 +19,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 UDM/Sql on the core #[arg(short = 'o', long = "output", default_value_t = String::from("output"))] output_file: String, /// The name of the nework @@ -44,9 +42,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 the ACC + #[arg(long = "acc", default_value_t = String::from("0020"))] + acc: String, /// 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, @@ -72,12 +70,19 @@ fn main() { print!(" {}", pysim_arg); } - if !wait_for_user(&format!("Please insert the sim-card with IMSI ending in: {}", imsi_ending.green())) { + if !wait_for_user(&format!( + "Please insert the sim-card with IMSI ending in: {}", + imsi_ending.green() + )) { exit_programm(1); } if args.dry_run { - println!("{}: The command is not executed since {} is enabled", "WARNING".yellow(), "dry_run".yellow()); + println!( + "{}: The command is not executed since {} is enabled", + "WARNING".yellow(), + "dry_run".yellow() + ); } else { let mut command = Command::new(&args.bin); for pysim_arg in pysim_args { @@ -96,19 +101,21 @@ fn main() { } } - // add command to be run on the open5gcore /* - * S = imsi - * k = Ki - * a = 8000 amf - * o = opc/op - * s = sqn (= 0) - * t = auth_type (= 0) - * 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 {}", + * S = imsi + * k = Ki + * a = 8000 amf + * o = opc/op + * s = sqn (= 000000000017) + * t = auth_type (= 0) + * c = op is opc + * u = usim_type (= 0) + * n = Domain Name (= mnc030.mcc999.3gppnetwork.org) + * T = MSISDN/Phone Number (= 49{imsi_ending}) + */ + let user_provision_command = format!( + "./provision_user.sh -S {} -k {} -a {} -o {} -s {} -t {} -c {} -u {} -n {} -T 49{}", String::from(&conf.IMSI), args.ki, "8000", @@ -119,7 +126,7 @@ fn main() { &args.opc } }, - "0", + "000000000017", "0", { if args.use_op { @@ -128,13 +135,17 @@ fn main() { "1" } }, - "0" + "0", + { + if args.mnc.len() == 3 { + format!("mnc{}.mcc{}.3gppnetwork.org", args.mnc, args.mcc) + } else { + format!("mnc0{}.mcc{}.3gppnetwork.org", args.mnc, args.mcc) + } + }, + imsi_ending ); - 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); } @@ -157,10 +168,8 @@ fn wait_for_user(msg: &str) -> bool { println!("\n{}\nPress enter to continue or 'a' to abort:", msg); 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') - } - Ok(_) => true, // other input is ignored + Ok(n) if n > 0 => !next_string.starts_with('a'), + Ok(_) => true, // other input is ignored Err(err) => panic!("{}", err), } } diff --git a/src/parser.rs b/src/parser.rs index c424855..1d95d5c 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,6 +1,6 @@ use std::error::Error; -use std::io::{self, BufRead}; use std::fs::File; +use std::io::{self, BufRead}; use std::path::Path; use csv::StringRecord; @@ -8,7 +8,6 @@ use serde::Deserialize; use crate::CliArgs; - #[derive(Deserialize, Debug, Clone)] // disable compiler warnings as this is just a struct to save data as it is in csv data #[allow(dead_code, non_snake_case)] @@ -39,7 +38,8 @@ pub fn get_imsi_ending(card_config: &mut CardValues) -> String { } pub fn update_imsi(card_config: &mut CardValues, cli_args: &CliArgs) { - card_config.IMSI = format!("{}{}{}", + card_config.IMSI = format!( + "{}{}{}", cli_args.mcc, cli_args.mnc, &card_config.IMSI[(cli_args.mnc.len() + cli_args.mcc.len())..] @@ -47,43 +47,24 @@ pub fn update_imsi(card_config: &mut CardValues, cli_args: &CliArgs) { } pub fn generate_pysim_args(card_config: &CardValues, cli_args: &CliArgs) -> Vec { - // calculate new imsi - let p = format!("-p{}", cli_args.device); - let imsi = format!("--imsi={}", card_config.IMSI); - let name = format!("--name=\"{}\"", cli_args.name); - let mnc = format!("--mnc={}", cli_args.mnc); - let mcc = format!("--mcc={}", cli_args.mcc); - let iccid = format!("--iccid={}", card_config.ICCID); - let pin_adm = format!("--pin-adm={}", card_config.ADM1); - let ki = format!("--ki={}", cli_args.ki); + // calculate new imsi + let p = format!("-p{}", cli_args.device); + let imsi = format!("--imsi={}", card_config.IMSI); + let name = format!("--name=\"{}\"", cli_args.name); + let mnc = format!("--mnc={}", cli_args.mnc); + let mcc = format!("--mcc={}", cli_args.mcc); + let iccid = format!("--iccid={}", card_config.ICCID); + let pin_adm = format!("--pin-adm={}", card_config.ADM1); + let ki = format!("--ki={}", cli_args.ki); + let acc = format!("--acc={}", cli_args.acc); - if cli_args.use_op { - let op = format!("--op={}", cli_args.op); - vec![ - p, - imsi, - name, - mnc, - mcc, - iccid, - pin_adm, - ki, - op - ] - } else { - let opc = format!("--opc={}", cli_args.opc); - vec![ - p, - imsi, - name, - mnc, - mcc, - iccid, - pin_adm, - ki, - opc - ] - } + if cli_args.use_op { + let op = format!("--op={}", cli_args.op); + vec![p, imsi, name, mnc, mcc, iccid, pin_adm, ki, acc, op] + } else { + let opc = format!("--opc={}", cli_args.opc); + vec![p, imsi, name, mnc, mcc, iccid, pin_adm, ki, acc, opc] + } } pub fn parse_csv(path: &str) -> Result, Box> { @@ -94,15 +75,17 @@ pub fn parse_csv(path: &str) -> Result, Box> { 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 record = StringRecord::from(line); - let sim_conf: CardValues = record.deserialize(Some(&header)).unwrap(); - sim_conf - }).collect()) + Ok(lines + .map(|line| { + // unpack line + let line = line.unwrap(); + 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 + }) + .collect()) } else { panic!("could not read csv"); } @@ -111,7 +94,9 @@ pub fn parse_csv(path: &str) -> Result, Box> { // The output is wrapped in a Result to allow matching on errors // Returns an Iterator to the Reader of the lines of the file. fn read_lines

(filename: P) -> io::Result>> -where P: AsRef, { +where + P: AsRef, +{ let file = File::open(filename)?; Ok(io::BufReader::new(file).lines()) }