Commit 60c8ef27 authored by Frédéric Leroy's avatar Frédéric Leroy

refactor(conf2uedata): separate processing and writing of data

parent 37f67630
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
#include "display.h" #include "display.h"
#include "fs.h" #include "fs.h"
const char *output_dir = NULL;
const char *msin = NULL; const char *msin = NULL;
const char *usim_api_k = NULL; const char *usim_api_k = NULL;
const char *msisdn = NULL; const char *msisdn = NULL;
...@@ -39,6 +37,7 @@ network_record_t* user_network_record_list = NULL; ...@@ -39,6 +37,7 @@ network_record_t* user_network_record_list = NULL;
int main(int argc, char**argv) { int main(int argc, char**argv) {
int option; int option;
const char* conf_file = NULL; const char* conf_file = NULL;
const char* output_dir = NULL;
const char options[]="c:o:h"; const char options[]="c:o:h";
while ((option = getopt(argc, argv, options)) != -1) { while ((option = getopt(argc, argv, options)) != -1) {
...@@ -70,7 +69,7 @@ int main(int argc, char**argv) { ...@@ -70,7 +69,7 @@ int main(int argc, char**argv) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if ( parse_config_file(conf_file) == EXIT_FAILURE ) { if ( parse_config_file(output_dir, conf_file) == EXIT_FAILURE ) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -79,7 +78,7 @@ int main(int argc, char**argv) { ...@@ -79,7 +78,7 @@ int main(int argc, char**argv) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
int parse_config_file(const char *filename) { int parse_config_file(const char *output_dir, const char *conf_filename) {
int rc = EXIT_SUCCESS; int rc = EXIT_SUCCESS;
int ret; int ret;
int ue_nb = 0; int ue_nb = 0;
...@@ -89,7 +88,7 @@ int parse_config_file(const char *filename) { ...@@ -89,7 +88,7 @@ int parse_config_file(const char *filename) {
char user[10]; char user[10];
config_t cfg; config_t cfg;
ret = get_config_from_file(filename, &cfg); ret = get_config_from_file(conf_filename, &cfg);
if (ret == EXIT_FAILURE) { if (ret == EXIT_FAILURE) {
exit(1); exit(1);
} }
...@@ -110,6 +109,10 @@ int parse_config_file(const char *filename) { ...@@ -110,6 +109,10 @@ int parse_config_file(const char *filename) {
fill_network_record_list(); fill_network_record_list();
for (int i = 0; i < ue_nb; i++) { for (int i = 0; i < ue_nb; i++) {
emm_nvdata_t emm_data;
user_nvdata_t user_data;
usim_data_t usim_data;
sprintf(user, "%s%d", UE, i); sprintf(user, "%s%d", UE, i);
ue_setting = config_setting_get_member(root_setting, user); ue_setting = config_setting_get_member(root_setting, user);
...@@ -118,11 +121,12 @@ int parse_config_file(const char *filename) { ...@@ -118,11 +121,12 @@ int parse_config_file(const char *filename) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
rc = parse_ue_user_param(ue_setting, i); rc = parse_ue_user_param(ue_setting, i, &user_data);
if (rc != EXIT_SUCCESS) { if (rc != EXIT_SUCCESS) {
printf("Problem in USER section for UE%d. EXITING...\n", i); printf("Problem in USER section for UE%d. EXITING...\n", i);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
write_user_data(output_dir, i, &user_data);
rc = parse_ue_sim_param(ue_setting, i); rc = parse_ue_sim_param(ue_setting, i);
if (rc != EXIT_SUCCESS) { if (rc != EXIT_SUCCESS) {
...@@ -134,9 +138,12 @@ int parse_config_file(const char *filename) { ...@@ -134,9 +138,12 @@ int parse_config_file(const char *filename) {
if (rc != EXIT_SUCCESS) { if (rc != EXIT_SUCCESS) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
gen_emm_data(i); gen_emm_data(i, &emm_data);
gen_usim_data(i); write_emm_data(output_dir, i, &emm_data);
}
gen_usim_data(&usim_data);
write_usim_data(output_dir, i, &usim_data);
}
config_destroy(&cfg); config_destroy(&cfg);
return(EXIT_SUCCESS); return(EXIT_SUCCESS);
} }
...@@ -161,142 +168,141 @@ int get_config_from_file(const char *filename, config_t *config) { ...@@ -161,142 +168,141 @@ int get_config_from_file(const char *filename, config_t *config) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void gen_usim_data(int user_id) { void gen_usim_data(usim_data_t *usim_data) {
usim_data_t usim_data = { }; memset(usim_data, 0, sizeof(usim_data_t));
memset(&usim_data, 0, sizeof(usim_data_t)); usim_data->imsi.length = 8;
usim_data.imsi.length = 8; usim_data->imsi.u.num.parity = get_msin_parity(msin);
usim_data.imsi.u.num.parity = get_msin_parity(msin);
usim_data.imsi.u.num.digit1 = user_plmn_list[hplmn_index].mcc[0]; usim_data->imsi.u.num.digit1 = user_plmn_list[hplmn_index].mcc[0];
usim_data.imsi.u.num.digit2 = user_plmn_list[hplmn_index].mcc[1]; usim_data->imsi.u.num.digit2 = user_plmn_list[hplmn_index].mcc[1];
usim_data.imsi.u.num.digit3 = user_plmn_list[hplmn_index].mcc[2]; usim_data->imsi.u.num.digit3 = user_plmn_list[hplmn_index].mcc[2];
usim_data.imsi.u.num.digit4 = user_plmn_list[hplmn_index].mnc[0]; usim_data->imsi.u.num.digit4 = user_plmn_list[hplmn_index].mnc[0];
usim_data.imsi.u.num.digit5 = user_plmn_list[hplmn_index].mnc[1]; usim_data->imsi.u.num.digit5 = user_plmn_list[hplmn_index].mnc[1];
if (strlen(user_plmn_list[hplmn_index].mnc) == 2) { if (strlen(user_plmn_list[hplmn_index].mnc) == 2) {
usim_data.imsi.u.num.digit6 = msin[0]; usim_data->imsi.u.num.digit6 = msin[0];
usim_data.imsi.u.num.digit7 = msin[1]; usim_data->imsi.u.num.digit7 = msin[1];
usim_data.imsi.u.num.digit8 = msin[2]; usim_data->imsi.u.num.digit8 = msin[2];
usim_data.imsi.u.num.digit9 = msin[3]; usim_data->imsi.u.num.digit9 = msin[3];
usim_data.imsi.u.num.digit10 = msin[4]; usim_data->imsi.u.num.digit10 = msin[4];
usim_data.imsi.u.num.digit11 = msin[5]; usim_data->imsi.u.num.digit11 = msin[5];
usim_data.imsi.u.num.digit12 = msin[6]; usim_data->imsi.u.num.digit12 = msin[6];
usim_data.imsi.u.num.digit13 = msin[7]; usim_data->imsi.u.num.digit13 = msin[7];
usim_data.imsi.u.num.digit14 = msin[8]; usim_data->imsi.u.num.digit14 = msin[8];
usim_data.imsi.u.num.digit15 = msin[9]; usim_data->imsi.u.num.digit15 = msin[9];
} else { } else {
usim_data.imsi.u.num.digit6 = user_plmn_list[hplmn_index].mnc[2]; usim_data->imsi.u.num.digit6 = user_plmn_list[hplmn_index].mnc[2];
usim_data.imsi.u.num.digit7 = msin[0]; usim_data->imsi.u.num.digit7 = msin[0];
usim_data.imsi.u.num.digit8 = msin[1]; usim_data->imsi.u.num.digit8 = msin[1];
usim_data.imsi.u.num.digit9 = msin[2]; usim_data->imsi.u.num.digit9 = msin[2];
usim_data.imsi.u.num.digit10 = msin[3]; usim_data->imsi.u.num.digit10 = msin[3];
usim_data.imsi.u.num.digit11 = msin[4]; usim_data->imsi.u.num.digit11 = msin[4];
usim_data.imsi.u.num.digit12 = msin[5]; usim_data->imsi.u.num.digit12 = msin[5];
usim_data.imsi.u.num.digit13 = msin[6]; usim_data->imsi.u.num.digit13 = msin[6];
usim_data.imsi.u.num.digit14 = msin[7]; usim_data->imsi.u.num.digit14 = msin[7];
usim_data.imsi.u.num.digit15 = msin[8]; usim_data->imsi.u.num.digit15 = msin[8];
} }
/* /*
* Ciphering and Integrity Keys * Ciphering and Integrity Keys
*/ */
usim_data.keys.ksi = KSI; usim_data->keys.ksi = KSI;
memset(&usim_data.keys.ck, 0, USIM_CK_SIZE); memset(&usim_data->keys.ck, 0, USIM_CK_SIZE);
memset(&usim_data.keys.ik, 0, USIM_IK_SIZE); memset(&usim_data->keys.ik, 0, USIM_IK_SIZE);
/* /*
* Higher Priority PLMN search period * Higher Priority PLMN search period
*/ */
usim_data.hpplmn = 0x00; /* Disable timer */ usim_data->hpplmn = 0x00; /* Disable timer */
/* /*
* List of Forbidden PLMNs * List of Forbidden PLMNs
*/ */
for (int i = 0; i < USIM_FPLMN_MAX; i++) { for (int i = 0; i < USIM_FPLMN_MAX; i++) {
memset(&usim_data.fplmn[i], 0xff, sizeof(plmn_t)); memset(&usim_data->fplmn[i], 0xff, sizeof(plmn_t));
} }
if (fplmn_nb > 0) { if (fplmn_nb > 0) {
for (int i = 0; i < fplmn_nb; i++) { for (int i = 0; i < fplmn_nb; i++) {
usim_data.fplmn[i] = user_network_record_list[fplmn[i]].plmn; usim_data->fplmn[i] = user_network_record_list[fplmn[i]].plmn;
} }
} }
/* /*
* Location Information * Location Information
*/ */
usim_data.loci.tmsi = DEFAULT_TMSI; usim_data->loci.tmsi = DEFAULT_TMSI;
usim_data.loci.lai.plmn = user_network_record_list[hplmn_index].plmn; usim_data->loci.lai.plmn = user_network_record_list[hplmn_index].plmn;
usim_data.loci.lai.lac = DEFAULT_LAC; usim_data->loci.lai.lac = DEFAULT_LAC;
usim_data.loci.status = USIM_LOCI_NOT_UPDATED; usim_data->loci.status = USIM_LOCI_NOT_UPDATED;
/* /*
* Packet Switched Location Information * Packet Switched Location Information
*/ */
usim_data.psloci.p_tmsi = DEFAULT_P_TMSI; usim_data->psloci.p_tmsi = DEFAULT_P_TMSI;
usim_data.psloci.signature[0] = 0x01; usim_data->psloci.signature[0] = 0x01;
usim_data.psloci.signature[1] = 0x02; usim_data->psloci.signature[1] = 0x02;
usim_data.psloci.signature[2] = 0x03; usim_data->psloci.signature[2] = 0x03;
usim_data.psloci.rai.plmn = user_network_record_list[hplmn_index].plmn; usim_data->psloci.rai.plmn = user_network_record_list[hplmn_index].plmn;
usim_data.psloci.rai.lac = DEFAULT_LAC; usim_data->psloci.rai.lac = DEFAULT_LAC;
usim_data.psloci.rai.rac = DEFAULT_RAC; usim_data->psloci.rai.rac = DEFAULT_RAC;
usim_data.psloci.status = USIM_PSLOCI_NOT_UPDATED; usim_data->psloci.status = USIM_PSLOCI_NOT_UPDATED;
/* /*
* Administrative Data * Administrative Data
*/ */
usim_data.ad.UE_Operation_Mode = USIM_NORMAL_MODE; usim_data->ad.UE_Operation_Mode = USIM_NORMAL_MODE;
usim_data.ad.Additional_Info = 0xffff; usim_data->ad.Additional_Info = 0xffff;
usim_data.ad.MNC_Length = strlen(user_plmn_list[hplmn_index].mnc); usim_data->ad.MNC_Length = strlen(user_plmn_list[hplmn_index].mnc);
/* /*
* EPS NAS security context * EPS NAS security context
*/ */
usim_data.securityctx.length = 52; usim_data->securityctx.length = 52;
usim_data.securityctx.KSIasme.type = USIM_KSI_ASME_TAG; usim_data->securityctx.KSIasme.type = USIM_KSI_ASME_TAG;
usim_data.securityctx.KSIasme.length = 1; usim_data->securityctx.KSIasme.length = 1;
usim_data.securityctx.KSIasme.value[0] = KSI_ASME; usim_data->securityctx.KSIasme.value[0] = KSI_ASME;
usim_data.securityctx.Kasme.type = USIM_K_ASME_TAG; usim_data->securityctx.Kasme.type = USIM_K_ASME_TAG;
usim_data.securityctx.Kasme.length = USIM_K_ASME_SIZE; usim_data->securityctx.Kasme.length = USIM_K_ASME_SIZE;
memset(usim_data.securityctx.Kasme.value, 0, memset(usim_data->securityctx.Kasme.value, 0,
usim_data.securityctx.Kasme.length); usim_data->securityctx.Kasme.length);
usim_data.securityctx.ulNAScount.type = USIM_UL_NAS_COUNT_TAG; usim_data->securityctx.ulNAScount.type = USIM_UL_NAS_COUNT_TAG;
usim_data.securityctx.ulNAScount.length = USIM_UL_NAS_COUNT_SIZE; usim_data->securityctx.ulNAScount.length = USIM_UL_NAS_COUNT_SIZE;
memset(usim_data.securityctx.ulNAScount.value, 0, memset(usim_data->securityctx.ulNAScount.value, 0,
usim_data.securityctx.ulNAScount.length); usim_data->securityctx.ulNAScount.length);
usim_data.securityctx.dlNAScount.type = USIM_DL_NAS_COUNT_TAG; usim_data->securityctx.dlNAScount.type = USIM_DL_NAS_COUNT_TAG;
usim_data.securityctx.dlNAScount.length = USIM_DL_NAS_COUNT_SIZE; usim_data->securityctx.dlNAScount.length = USIM_DL_NAS_COUNT_SIZE;
memset(usim_data.securityctx.dlNAScount.value, 0, memset(usim_data->securityctx.dlNAScount.value, 0,
usim_data.securityctx.dlNAScount.length); usim_data->securityctx.dlNAScount.length);
usim_data.securityctx.algorithmID.type = USIM_INT_ENC_ALGORITHMS_TAG; usim_data->securityctx.algorithmID.type = USIM_INT_ENC_ALGORITHMS_TAG;
usim_data.securityctx.algorithmID.length = 1; usim_data->securityctx.algorithmID.length = 1;
usim_data.securityctx.algorithmID.value[0] = SECURITY_ALGORITHMS; usim_data->securityctx.algorithmID.value[0] = SECURITY_ALGORITHMS;
/* /*
* Subcriber's Number * Subcriber's Number
*/ */
usim_data.msisdn.length = 7; usim_data->msisdn.length = 7;
usim_data.msisdn.number.ext = 1; usim_data->msisdn.number.ext = 1;
usim_data.msisdn.number.ton = MSISDN_TON_UNKNOWKN; usim_data->msisdn.number.ton = MSISDN_TON_UNKNOWKN;
usim_data.msisdn.number.npi = MSISDN_NPI_ISDN_TELEPHONY; usim_data->msisdn.number.npi = MSISDN_NPI_ISDN_TELEPHONY;
usim_data.msisdn.conf1_record_id = 0xff; /* Not used */ usim_data->msisdn.conf1_record_id = 0xff; /* Not used */
usim_data.msisdn.ext1_record_id = 0xff; /* Not used */ usim_data->msisdn.ext1_record_id = 0xff; /* Not used */
int j = 0; int j = 0;
for (int i = 0; i < strlen(msisdn); i += 2) { for (int i = 0; i < strlen(msisdn); i += 2) {
usim_data.msisdn.number.digit[j].msb = msisdn[i]; usim_data->msisdn.number.digit[j].msb = msisdn[i];
j++; j++;
} }
j = 0; j = 0;
for (int i = 1; i < strlen(msisdn); i += 2) { for (int i = 1; i < strlen(msisdn); i += 2) {
usim_data.msisdn.number.digit[j].lsb = msisdn[i]; usim_data->msisdn.number.digit[j].lsb = msisdn[i];
j++; j++;
} }
if (strlen(msisdn) % 2 == 0) { if (strlen(msisdn) % 2 == 0) {
for (int i = strlen(msisdn) / 2; i < 10; i++) { for (int i = strlen(msisdn) / 2; i < 10; i++) {
usim_data.msisdn.number.digit[i].msb = 0xf; usim_data->msisdn.number.digit[i].msb = 0xf;
usim_data.msisdn.number.digit[i].lsb = 0xf; usim_data->msisdn.number.digit[i].lsb = 0xf;
} }
} else { } else {
usim_data.msisdn.number.digit[strlen(msisdn) / 2].lsb = 0xf; usim_data->msisdn.number.digit[strlen(msisdn) / 2].lsb = 0xf;
for (int i = (strlen(msisdn) / 2) + 1; i < 10; i++) { for (int i = (strlen(msisdn) / 2) + 1; i < 10; i++) {
usim_data.msisdn.number.digit[i].msb = 0xf; usim_data->msisdn.number.digit[i].msb = 0xf;
usim_data.msisdn.number.digit[i].lsb = 0xf; usim_data->msisdn.number.digit[i].lsb = 0xf;
} }
} }
/* /*
...@@ -304,22 +310,22 @@ void gen_usim_data(int user_id) { ...@@ -304,22 +310,22 @@ void gen_usim_data(int user_id) {
*/ */
for (int i = 0; i < oplmn_nb; i++) { for (int i = 0; i < oplmn_nb; i++) {
network_record_t record = user_network_record_list[oplmn[i]]; network_record_t record = user_network_record_list[oplmn[i]];
usim_data.pnn[i].fullname.type = USIM_PNN_FULLNAME_TAG; usim_data->pnn[i].fullname.type = USIM_PNN_FULLNAME_TAG;
usim_data.pnn[i].fullname.length = strlen(record.fullname); usim_data->pnn[i].fullname.length = strlen(record.fullname);
strncpy((char*) usim_data.pnn[i].fullname.value, record.fullname, strncpy((char*) usim_data->pnn[i].fullname.value, record.fullname,
usim_data.pnn[i].fullname.length); usim_data->pnn[i].fullname.length);
usim_data.pnn[i].shortname.type = USIM_PNN_SHORTNAME_TAG; usim_data->pnn[i].shortname.type = USIM_PNN_SHORTNAME_TAG;
usim_data.pnn[i].shortname.length = strlen(record.shortname); usim_data->pnn[i].shortname.length = strlen(record.shortname);
strncpy((char*) usim_data.pnn[i].shortname.value, record.shortname, strncpy((char*) usim_data->pnn[i].shortname.value, record.shortname,
usim_data.pnn[i].shortname.length); usim_data->pnn[i].shortname.length);
usim_data.opl[i].plmn = record.plmn; usim_data->opl[i].plmn = record.plmn;
usim_data.opl[i].start = record.tac_start; usim_data->opl[i].start = record.tac_start;
usim_data.opl[i].end = record.tac_end; usim_data->opl[i].end = record.tac_end;
usim_data.opl[i].record_id = i; usim_data->opl[i].record_id = i;
} }
if (oplmn_nb < USIM_OPL_MAX) { if (oplmn_nb < USIM_OPL_MAX) {
for (int i = oplmn_nb; i < USIM_OPL_MAX; i++) { for (int i = oplmn_nb; i < USIM_OPL_MAX; i++) {
memset(&usim_data.opl[i].plmn, 0xff, sizeof(plmn_t)); memset(&usim_data->opl[i].plmn, 0xff, sizeof(plmn_t));
} }
} }
...@@ -327,155 +333,162 @@ void gen_usim_data(int user_id) { ...@@ -327,155 +333,162 @@ void gen_usim_data(int user_id) {
* List of Equivalent HPLMNs * List of Equivalent HPLMNs
*/ */
for (int i = 0; i < ehplmn_nb; i++) { for (int i = 0; i < ehplmn_nb; i++) {
usim_data.ehplmn[i] = user_network_record_list[ehplmn[i]].plmn; usim_data->ehplmn[i] = user_network_record_list[ehplmn[i]].plmn;
} }
if (ehplmn_nb < USIM_EHPLMN_MAX) { if (ehplmn_nb < USIM_EHPLMN_MAX) {
for (int i = ehplmn_nb; i < USIM_EHPLMN_MAX; i++) { for (int i = ehplmn_nb; i < USIM_EHPLMN_MAX; i++) {
memset(&usim_data.ehplmn[i], 0xff, sizeof(plmn_t)); memset(&usim_data->ehplmn[i], 0xff, sizeof(plmn_t));
} }
} }
/* /*
* Home PLMN Selector with Access Technology * Home PLMN Selector with Access Technology
*/ */
usim_data.hplmn.plmn = user_network_record_list[hplmn_index].plmn; usim_data->hplmn.plmn = user_network_record_list[hplmn_index].plmn;
usim_data.hplmn.AcT = (USIM_ACT_GSM | USIM_ACT_UTRAN | USIM_ACT_EUTRAN); usim_data->hplmn.AcT = (USIM_ACT_GSM | USIM_ACT_UTRAN | USIM_ACT_EUTRAN);
/* /*
* List of user controlled PLMN selector with Access Technology * List of user controlled PLMN selector with Access Technology
*/ */
for (int i = 0; i < USIM_PLMN_MAX; i++) { for (int i = 0; i < USIM_PLMN_MAX; i++) {
memset(&usim_data.plmn[i], 0xff, sizeof(plmn_t)); memset(&usim_data->plmn[i], 0xff, sizeof(plmn_t));
} }
if (ucplmn_nb > 0) { if (ucplmn_nb > 0) {
for (int i = 0; i < ucplmn_nb; i++) { for (int i = 0; i < ucplmn_nb; i++) {
usim_data.plmn[i].plmn = user_network_record_list[ucplmn[i]].plmn; usim_data->plmn[i].plmn = user_network_record_list[ucplmn[i]].plmn;
} }
} }
// List of operator controlled PLMN selector with Access Technology // List of operator controlled PLMN selector with Access Technology
for (int i = 0; i < USIM_OPLMN_MAX; i++) { for (int i = 0; i < USIM_OPLMN_MAX; i++) {
memset(&usim_data.oplmn[i], 0xff, sizeof(plmn_t)); memset(&usim_data->oplmn[i], 0xff, sizeof(plmn_t));
} }
if (ocplmn_nb > 0) { if (ocplmn_nb > 0) {
for (int i = 0; i < ocplmn_nb; i++) { for (int i = 0; i < ocplmn_nb; i++) {
usim_data.oplmn[i].plmn = user_network_record_list[ocplmn[i]].plmn; usim_data->oplmn[i].plmn = user_network_record_list[ocplmn[i]].plmn;
usim_data.oplmn[i].AcT = (USIM_ACT_GSM | USIM_ACT_UTRAN usim_data->oplmn[i].AcT = (USIM_ACT_GSM | USIM_ACT_UTRAN
| USIM_ACT_EUTRAN); | USIM_ACT_EUTRAN);
} }
} }
/* /*
* EPS Location Information * EPS Location Information
*/ */
usim_data.epsloci.guti.gummei.plmn = usim_data->epsloci.guti.gummei.plmn =
user_network_record_list[hplmn_index].plmn; user_network_record_list[hplmn_index].plmn;
usim_data.epsloci.guti.gummei.MMEgid = DEFAULT_MME_ID; usim_data->epsloci.guti.gummei.MMEgid = DEFAULT_MME_ID;
usim_data.epsloci.guti.gummei.MMEcode = DEFAULT_MME_CODE; usim_data->epsloci.guti.gummei.MMEcode = DEFAULT_MME_CODE;
usim_data.epsloci.guti.m_tmsi = DEFAULT_M_TMSI; usim_data->epsloci.guti.m_tmsi = DEFAULT_M_TMSI;
usim_data.epsloci.tai.plmn = usim_data.epsloci.guti.gummei.plmn; usim_data->epsloci.tai.plmn = usim_data->epsloci.guti.gummei.plmn;
usim_data.epsloci.tai.tac = DEFAULT_TAC; usim_data->epsloci.tai.tac = DEFAULT_TAC;
usim_data.epsloci.status = USIM_EPSLOCI_UPDATED; usim_data->epsloci.status = USIM_EPSLOCI_UPDATED;
/* /*
* Non-Access Stratum configuration * Non-Access Stratum configuration
*/ */
usim_data.nasconfig.NAS_SignallingPriority.type = usim_data->nasconfig.NAS_SignallingPriority.type =
USIM_NAS_SIGNALLING_PRIORITY_TAG; USIM_NAS_SIGNALLING_PRIORITY_TAG;
usim_data.nasconfig.NAS_SignallingPriority.length = 1; usim_data->nasconfig.NAS_SignallingPriority.length = 1;
usim_data.nasconfig.NAS_SignallingPriority.value[0] = 0x00; usim_data->nasconfig.NAS_SignallingPriority.value[0] = 0x00;
usim_data.nasconfig.NMO_I_Behaviour.type = USIM_NMO_I_BEHAVIOUR_TAG; usim_data->nasconfig.NMO_I_Behaviour.type = USIM_NMO_I_BEHAVIOUR_TAG;
usim_data.nasconfig.NMO_I_Behaviour.length = 1; usim_data->nasconfig.NMO_I_Behaviour.length = 1;
usim_data.nasconfig.NMO_I_Behaviour.value[0] = 0x00; usim_data->nasconfig.NMO_I_Behaviour.value[0] = 0x00;
usim_data.nasconfig.AttachWithImsi.type = USIM_ATTACH_WITH_IMSI_TAG; usim_data->nasconfig.AttachWithImsi.type = USIM_ATTACH_WITH_IMSI_TAG;
usim_data.nasconfig.AttachWithImsi.length = 1; usim_data->nasconfig.AttachWithImsi.length = 1;
#if defined(START_WITH_GUTI) #if defined(START_WITH_GUTI)
usim_data.nasconfig.AttachWithImsi.value[0] = 0x00; usim_data->nasconfig.AttachWithImsi.value[0] = 0x00;
#else #else
usim_data.nasconfig.AttachWithImsi.value[0] = 0x01; usim_data->nasconfig.AttachWithImsi.value[0] = 0x01;
#endif #endif
usim_data.nasconfig.MinimumPeriodicSearchTimer.type = usim_data->nasconfig.MinimumPeriodicSearchTimer.type =
USIM_MINIMUM_PERIODIC_SEARCH_TIMER_TAG; USIM_MINIMUM_PERIODIC_SEARCH_TIMER_TAG;
usim_data.nasconfig.MinimumPeriodicSearchTimer.length = 1; usim_data->nasconfig.MinimumPeriodicSearchTimer.length = 1;
usim_data.nasconfig.MinimumPeriodicSearchTimer.value[0] = 0x00; usim_data->nasconfig.MinimumPeriodicSearchTimer.value[0] = 0x00;
usim_data.nasconfig.ExtendedAccessBarring.type = usim_data->nasconfig.ExtendedAccessBarring.type =
USIM_EXTENDED_ACCESS_BARRING_TAG; USIM_EXTENDED_ACCESS_BARRING_TAG;
usim_data.nasconfig.ExtendedAccessBarring.length = 1; usim_data->nasconfig.ExtendedAccessBarring.length = 1;
usim_data.nasconfig.ExtendedAccessBarring.value[0] = 0x00; usim_data->nasconfig.ExtendedAccessBarring.value[0] = 0x00;
usim_data.nasconfig.Timer_T3245_Behaviour.type = usim_data->nasconfig.Timer_T3245_Behaviour.type =
USIM_TIMER_T3245_BEHAVIOUR_TAG; USIM_TIMER_T3245_BEHAVIOUR_TAG;
usim_data.nasconfig.Timer_T3245_Behaviour.length = 1; usim_data->nasconfig.Timer_T3245_Behaviour.length = 1;
usim_data.nasconfig.Timer_T3245_Behaviour.value[0] = 0x00; usim_data->nasconfig.Timer_T3245_Behaviour.value[0] = 0x00;
/* initialize the subscriber authentication security key */ /* initialize the subscriber authentication security key */
hex_string_to_hex_value(usim_data.keys.usim_api_k, hex_string_to_hex_value(usim_data->keys.usim_api_k,
usim_api_k, USIM_API_K_SIZE); usim_api_k, USIM_API_K_SIZE);
hex_string_to_hex_value(usim_data.keys.opc, opc, hex_string_to_hex_value(usim_data->keys.opc, opc,
OPC_SIZE); OPC_SIZE);
}
char *path = make_filename(output_dir, USIM_API_NVRAM_FILENAME, user_id); int write_usim_data(const char *directory, int user_id, usim_data_t *usim_data){
usim_api_write(path, &usim_data); int rc;
free(path); char *filename = make_filename(directory, USIM_API_NVRAM_FILENAME, user_id);
rc = usim_api_write(filename, usim_data);
free(filename);
return rc;
} }
void gen_emm_data(int user_id) {
void gen_emm_data(int user_id, emm_nvdata_t *emm_data) {
hplmn_index = get_plmn_index(hplmn); hplmn_index = get_plmn_index(hplmn);
emm_nvdata_t emm_data; memset(emm_data, 0, sizeof(emm_nvdata_t));
int rc;
memset(&emm_data, 0, sizeof(emm_nvdata_t));
int hplmn_index = get_plmn_index(hplmn); int hplmn_index = get_plmn_index(hplmn);
emm_data.imsi.length = 8; emm_data->imsi.length = 8;
emm_data.imsi.u.num.parity = get_msin_parity(msin); emm_data->imsi.u.num.parity = get_msin_parity(msin);
emm_data.imsi.u.num.digit1 = user_plmn_list[hplmn_index].mcc[0]; emm_data->imsi.u.num.digit1 = user_plmn_list[hplmn_index].mcc[0];
emm_data.imsi.u.num.digit2 = user_plmn_list[hplmn_index].mcc[1]; emm_data->imsi.u.num.digit2 = user_plmn_list[hplmn_index].mcc[1];
emm_data.imsi.u.num.digit3 = user_plmn_list[hplmn_index].mcc[2]; emm_data->imsi.u.num.digit3 = user_plmn_list[hplmn_index].mcc[2];
emm_data.imsi.u.num.digit4 = user_plmn_list[hplmn_index].mnc[0]; emm_data->imsi.u.num.digit4 = user_plmn_list[hplmn_index].mnc[0];
emm_data.imsi.u.num.digit5 = user_plmn_list[hplmn_index].mnc[1]; emm_data->imsi.u.num.digit5 = user_plmn_list[hplmn_index].mnc[1];
if (strlen(user_plmn_list[hplmn_index].mnc) == 3) { if (strlen(user_plmn_list[hplmn_index].mnc) == 3) {
emm_data.rplmn.MNCdigit3 = user_plmn_list[hplmn_index].mnc[2]; emm_data->rplmn.MNCdigit3 = user_plmn_list[hplmn_index].mnc[2];
emm_data.imsi.u.num.digit6 = user_plmn_list[hplmn_index].mnc[2]; emm_data->imsi.u.num.digit6 = user_plmn_list[hplmn_index].mnc[2];
emm_data.imsi.u.num.digit7 = msin[0]; emm_data->imsi.u.num.digit7 = msin[0];
emm_data.imsi.u.num.digit8 = msin[1]; emm_data->imsi.u.num.digit8 = msin[1];
emm_data.imsi.u.num.digit9 = msin[2]; emm_data->imsi.u.num.digit9 = msin[2];
emm_data.imsi.u.num.digit10 = msin[3]; emm_data->imsi.u.num.digit10 = msin[3];
emm_data.imsi.u.num.digit11 = msin[4]; emm_data->imsi.u.num.digit11 = msin[4];
emm_data.imsi.u.num.digit12 = msin[5]; emm_data->imsi.u.num.digit12 = msin[5];
emm_data.imsi.u.num.digit13 = msin[6]; emm_data->imsi.u.num.digit13 = msin[6];
emm_data.imsi.u.num.digit14 = msin[7]; emm_data->imsi.u.num.digit14 = msin[7];
emm_data.imsi.u.num.digit15 = msin[8]; emm_data->imsi.u.num.digit15 = msin[8];
} else { } else {
emm_data.rplmn.MNCdigit3 = 0xf; emm_data->rplmn.MNCdigit3 = 0xf;
emm_data.imsi.u.num.digit6 = msin[0]; emm_data->imsi.u.num.digit6 = msin[0];
emm_data.imsi.u.num.digit7 = msin[1]; emm_data->imsi.u.num.digit7 = msin[1];
emm_data.imsi.u.num.digit8 = msin[2]; emm_data->imsi.u.num.digit8 = msin[2];
emm_data.imsi.u.num.digit9 = msin[3]; emm_data->imsi.u.num.digit9 = msin[3];
emm_data.imsi.u.num.digit10 = msin[4]; emm_data->imsi.u.num.digit10 = msin[4];
emm_data.imsi.u.num.digit11 = msin[5]; emm_data->imsi.u.num.digit11 = msin[5];
emm_data.imsi.u.num.digit12 = msin[6]; emm_data->imsi.u.num.digit12 = msin[6];
emm_data.imsi.u.num.digit13 = msin[7]; emm_data->imsi.u.num.digit13 = msin[7];
emm_data.imsi.u.num.digit14 = msin[8]; emm_data->imsi.u.num.digit14 = msin[8];
emm_data.imsi.u.num.digit15 = msin[9]; emm_data->imsi.u.num.digit15 = msin[9];
} }
emm_data.rplmn.MCCdigit1 = user_plmn_list[hplmn_index].mcc[0]; emm_data->rplmn.MCCdigit1 = user_plmn_list[hplmn_index].mcc[0];
emm_data.rplmn.MCCdigit2 = user_plmn_list[hplmn_index].mcc[1]; emm_data->rplmn.MCCdigit2 = user_plmn_list[hplmn_index].mcc[1];
emm_data.rplmn.MCCdigit3 = user_plmn_list[hplmn_index].mcc[2]; emm_data->rplmn.MCCdigit3 = user_plmn_list[hplmn_index].mcc[2];
emm_data.rplmn.MNCdigit1 = user_plmn_list[hplmn_index].mnc[0]; emm_data->rplmn.MNCdigit1 = user_plmn_list[hplmn_index].mnc[0];
emm_data.rplmn.MNCdigit2 = user_plmn_list[hplmn_index].mnc[1]; emm_data->rplmn.MNCdigit2 = user_plmn_list[hplmn_index].mnc[1];
emm_data.eplmn.n_plmns = ehplmn_nb; emm_data->eplmn.n_plmns = ehplmn_nb;
}
char* path = make_filename(output_dir, EMM_NVRAM_FILENAME, user_id); int write_emm_data(const char *directory, int user_id, emm_nvdata_t *emm_data) {
rc = memory_write(path, &emm_data, sizeof(emm_nvdata_t)); int rc;
free(path); char* filename = make_filename(directory, EMM_NVRAM_FILENAME, user_id);
rc = memory_write(filename, emm_data, sizeof(emm_nvdata_t));
free(filename);
if (rc != RETURNok) { if (rc != RETURNok) {
perror("ERROR\t: memory_write() failed"); perror("ERROR\t: memory_write() failed");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
return(EXIT_SUCCESS);
} }
int parse_plmn_param(config_setting_t *plmn_setting, int index) { int parse_plmn_param(config_setting_t *plmn_setting, int index) {
...@@ -632,9 +645,8 @@ int parse_ue_sim_param(config_setting_t *ue_setting, int user_id) { ...@@ -632,9 +645,8 @@ int parse_ue_sim_param(config_setting_t *ue_setting, int user_id) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
int parse_ue_user_param(config_setting_t *ue_setting, int user_id) { int parse_ue_user_param(config_setting_t *ue_setting, int user_id, user_nvdata_t *user_data) {
config_setting_t *ue_param_setting = NULL; config_setting_t *ue_param_setting = NULL;
user_nvdata_t user_data;
const char* imei = NULL; const char* imei = NULL;
const char* manufacturer = NULL; const char* manufacturer = NULL;
const char* model = NULL; const char* model = NULL;
...@@ -667,29 +679,34 @@ int parse_ue_user_param(config_setting_t *ue_setting, int user_id) { ...@@ -667,29 +679,34 @@ int parse_ue_user_param(config_setting_t *ue_setting, int user_id) {
printf("Check USER PIN for UE%d FULLNAME. Exiting\n", user_id); printf("Check USER PIN for UE%d FULLNAME. Exiting\n", user_id);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
memset(&user_data, 0, sizeof(user_nvdata_t));
snprintf(user_data.IMEI, USER_IMEI_SIZE + 1, "%s%d", imei, _luhn(imei)); memset(user_data, 0, sizeof(user_nvdata_t));
snprintf(user_data->IMEI, USER_IMEI_SIZE + 1, "%s%d", imei, _luhn(imei));
/* /*
* Manufacturer identifier * Manufacturer identifier
*/ */
strncpy(user_data.manufacturer, manufacturer, USER_MANUFACTURER_SIZE); strncpy(user_data->manufacturer, manufacturer, USER_MANUFACTURER_SIZE);
/* /*
* Model identifier * Model identifier
*/ */
strncpy(user_data.model, model, USER_MODEL_SIZE); strncpy(user_data->model, model, USER_MODEL_SIZE);
/* /*
* SIM Personal Identification Number * SIM Personal Identification Number
*/ */
strncpy(user_data.PIN, pin, USER_PIN_SIZE); strncpy(user_data->PIN, pin, USER_PIN_SIZE);
char* path = make_filename(output_dir, USER_NVRAM_FILENAME, user_id); return EXIT_SUCCESS;
rc = memory_write(path, &user_data, sizeof(user_nvdata_t)); }
free(path);
void write_user_data(const char *directory, int user_id, user_nvdata_t *data) {
int rc;
char* filename = make_filename(directory, USER_NVRAM_FILENAME, user_id);
rc = memory_write(filename, data, sizeof(user_nvdata_t));
free(filename);
if (rc != RETURNok) { if (rc != RETURNok) {
perror("ERROR\t: memory_write() failed"); perror("ERROR\t: memory_write() failed");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
return EXIT_SUCCESS;
} }
int fill_ucplmn(config_setting_t* setting, int user_id) { int fill_ucplmn(config_setting_t* setting, int user_id) {
......
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
#define _CONF2UEDATA_H #define _CONF2UEDATA_H
#include <libconfig.h> #include <libconfig.h>
#include "emmData.h" #include "emmData.h"
#include "usim_api.h"
#include "userDef.h"
#define USER "USER" #define USER "USER"
#define UE "UE" #define UE "UE"
...@@ -70,8 +73,6 @@ typedef struct { ...@@ -70,8 +73,6 @@ typedef struct {
const char *mcc; const char *mcc;
} plmn_conf_param_t; } plmn_conf_param_t;
extern const char* output_dir;
extern const char *msin; extern const char *msin;
extern const char *usim_api_k; extern const char *usim_api_k;
extern const char *msisdn; extern const char *msisdn;
...@@ -96,16 +97,21 @@ extern plmn_conf_param_t* user_plmn_list; ...@@ -96,16 +97,21 @@ extern plmn_conf_param_t* user_plmn_list;
extern network_record_t* user_network_record_list; extern network_record_t* user_network_record_list;
int get_config_from_file(const char *filename, config_t *config); int get_config_from_file(const char *filename, config_t *config);
int parse_config_file(const char *filename); int parse_config_file(const char *output_dir, const char *filename);
void _display_usage(void); void _display_usage(void);
void gen_emm_data(int user_id) ; void gen_emm_data(int user_id, emm_nvdata_t *emm_data);
void gen_usim_data(int user_id);
void fill_network_record_list(void); void fill_network_record_list(void);
int parse_ue_user_param(config_setting_t *ue_setting, int user_id, user_nvdata_t *user_data);
void write_user_data(const char *directory, int user_id, user_nvdata_t *data);
int write_emm_data(const char *directory, int user_id, emm_nvdata_t *emm_data);
int write_usim_data(const char *directory, int user_id, usim_data_t *usim_data);
void gen_usim_data(usim_data_t *usim_data);
int _luhn(const char* cc); int _luhn(const char* cc);
int parse_ue_user_param(config_setting_t *ue_setting, int user_id);
int parse_ue_sim_param(config_setting_t *ue_setting, int user_id); int parse_ue_sim_param(config_setting_t *ue_setting, int user_id);
int parse_plmn_param(config_setting_t *plmn_setting, int index); int parse_plmn_param(config_setting_t *plmn_setting, int index);
int parse_plmns(config_setting_t *all_plmn_setting); int parse_plmns(config_setting_t *all_plmn_setting);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment