Compare commits

..

1 Commits
master ... main

Author SHA1 Message Date
Julius Herrmann
1a08d11b09 update to rel 7.4 of OpenCore 2023-06-22 20:54:28 +02:00
4 changed files with 78 additions and 82 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
SIM_config.csv

View File

@ -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

View File

@ -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),
}
}

View File

@ -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<String> {
// 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<Vec<CardValues>, Box<dyn Error>> {
@ -94,15 +75,17 @@ pub fn parse_csv(path: &str) -> Result<Vec<CardValues>, Box<dyn Error>> {
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<Vec<CardValues>, Box<dyn Error>> {
// 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<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
where P: AsRef<Path>, {
where
P: AsRef<Path>,
{
let file = File::open(filename)?;
Ok(io::BufReader::new(file).lines())
}