Commit 459a6ec3 authored by Frédéric Leroy's avatar Frédéric Leroy

refactor(conf2uedata): use user_plmns struct to store plmns lists

This remove the old static lists
parent c86b437e
...@@ -12,12 +12,6 @@ ...@@ -12,12 +12,6 @@
#include "conf_user_data.h" #include "conf_user_data.h"
#include "conf_usim.h" #include "conf_usim.h"
plmns_list ucplmns;
plmns_list oplmns;
plmns_list ocplmns;
plmns_list fplmns;
plmns_list ehplmns;
int plmn_nb = 0; int plmn_nb = 0;
plmn_conf_param_t* user_plmn_list=NULL; plmn_conf_param_t* user_plmn_list=NULL;
...@@ -106,6 +100,8 @@ int parse_config_file(const char *output_dir, const char *conf_filename) { ...@@ -106,6 +100,8 @@ int parse_config_file(const char *output_dir, const char *conf_filename) {
usim_data_t usim_data; usim_data_t usim_data;
usim_data_conf_t usim_data_conf; usim_data_conf_t usim_data_conf;
user_plmns_t user_plmns;
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);
...@@ -114,7 +110,7 @@ int parse_config_file(const char *output_dir, const char *conf_filename) { ...@@ -114,7 +110,7 @@ int parse_config_file(const char *output_dir, const char *conf_filename) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
rc = parse_ue_plmn_param(ue_setting, i, &usim_data_conf.hplmn); rc = parse_user_plmns_conf(ue_setting, i, &user_plmns, &usim_data_conf.hplmn);
if (rc != EXIT_SUCCESS) { if (rc != EXIT_SUCCESS) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -132,10 +128,10 @@ int parse_config_file(const char *output_dir, const char *conf_filename) { ...@@ -132,10 +128,10 @@ int parse_config_file(const char *output_dir, const char *conf_filename) {
printf("Problem in SIM section for UE%d. EXITING...\n", i); printf("Problem in SIM section for UE%d. EXITING...\n", i);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
gen_usim_data(&usim_data_conf, &usim_data); gen_usim_data(&usim_data_conf, &usim_data, &user_plmns);
write_usim_data(output_dir, i, &usim_data); write_usim_data(output_dir, i, &usim_data);
gen_emm_data(&emm_data, usim_data_conf.hplmn, usim_data_conf.msin); gen_emm_data(&emm_data, usim_data_conf.hplmn, usim_data_conf.msin, user_plmns.equivalents_home.size);
write_emm_data(output_dir, i, &emm_data); write_emm_data(output_dir, i, &emm_data);
} }
...@@ -221,7 +217,8 @@ int parse_plmns(config_setting_t *all_plmn_setting) { ...@@ -221,7 +217,8 @@ int parse_plmns(config_setting_t *all_plmn_setting) {
return rc; return rc;
} }
int parse_ue_plmn_param(config_setting_t *ue_setting, int user_id, const char **h) { int parse_user_plmns_conf(config_setting_t *ue_setting, int user_id,
user_plmns_t *user_plmns, const char **h) {
int nb_errors = 0; int nb_errors = 0;
const char *hplmn; const char *hplmn;
...@@ -236,15 +233,15 @@ int parse_ue_plmn_param(config_setting_t *ue_setting, int user_id, const char ** ...@@ -236,15 +233,15 @@ int parse_ue_plmn_param(config_setting_t *ue_setting, int user_id, const char **
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if ( parse_Xplmn(ue_setting, UCPLMN, user_id, &ucplmns) == EXIT_FAILURE ) if ( parse_Xplmn(ue_setting, UCPLMN, user_id, &user_plmns->users_controlled) == EXIT_FAILURE )
nb_errors++; nb_errors++;
if ( parse_Xplmn(ue_setting, OPLMN, user_id, &oplmns) == EXIT_FAILURE ) if ( parse_Xplmn(ue_setting, OPLMN, user_id, &user_plmns->operators) == EXIT_FAILURE )
nb_errors++; nb_errors++;
if ( parse_Xplmn(ue_setting, OCPLMN, user_id, &ocplmns) == EXIT_FAILURE ) if ( parse_Xplmn(ue_setting, OCPLMN, user_id, &user_plmns->operators_controlled) == EXIT_FAILURE )
nb_errors++; nb_errors++;
if ( parse_Xplmn(ue_setting, FPLMN, user_id, &fplmns) == EXIT_FAILURE ) if ( parse_Xplmn(ue_setting, FPLMN, user_id, &user_plmns->forbiddens) == EXIT_FAILURE )
nb_errors++; nb_errors++;
if ( parse_Xplmn(ue_setting, EHPLMN, user_id, &ehplmns) == EXIT_FAILURE ) if ( parse_Xplmn(ue_setting, EHPLMN, user_id, &user_plmns->equivalents_home) == EXIT_FAILURE )
nb_errors++; nb_errors++;
if ( nb_errors > 0 ) if ( nb_errors > 0 )
......
...@@ -48,11 +48,13 @@ typedef struct { ...@@ -48,11 +48,13 @@ typedef struct {
int *items; int *items;
} plmns_list; } plmns_list;
extern plmns_list ucplmns; typedef struct {
extern plmns_list oplmns; plmns_list users_controlled;
extern plmns_list ocplmns; plmns_list operators;
extern plmns_list fplmns; plmns_list operators_controlled;
extern plmns_list ehplmns; plmns_list forbiddens;
plmns_list equivalents_home;
} user_plmns_t;
extern int plmn_nb; extern int plmn_nb;
...@@ -68,7 +70,8 @@ void fill_network_record_list(void); ...@@ -68,7 +70,8 @@ void fill_network_record_list(void);
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);
int get_plmn_index(const char * mccmnc); int get_plmn_index(const char * mccmnc);
int parse_ue_plmn_param(config_setting_t *ue_setting, int user_id, const char **hplmn); int parse_user_plmns_conf(config_setting_t *ue_setting, int user_id,
user_plmns_t *user_plmns, const char **h);
int parse_Xplmn(config_setting_t *ue_setting, const char *section, int parse_Xplmn(config_setting_t *ue_setting, const char *section,
int user_id, plmns_list *plmns); int user_id, plmns_list *plmns);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "conf_emm.h" #include "conf_emm.h"
#include "fs.h" #include "fs.h"
void gen_emm_data(emm_nvdata_t *emm_data, const char *hplmn, const char *msin) { void gen_emm_data(emm_nvdata_t *emm_data, const char *hplmn, const char *msin, int ehplmn_count) {
memset(emm_data, 0, sizeof(emm_nvdata_t)); 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;
...@@ -53,7 +53,7 @@ void gen_emm_data(emm_nvdata_t *emm_data, const char *hplmn, const char *msin) { ...@@ -53,7 +53,7 @@ void gen_emm_data(emm_nvdata_t *emm_data, const char *hplmn, const char *msin) {
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 = ehplmns.size; emm_data->eplmn.n_plmns = ehplmn_count;
} }
int write_emm_data(const char *directory, int user_id, emm_nvdata_t *emm_data) { int write_emm_data(const char *directory, int user_id, emm_nvdata_t *emm_data) {
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
#include "emmData.h" #include "emmData.h"
void gen_emm_data(emm_nvdata_t *emm_data, const char *hplmn, const char *msin); void gen_emm_data(emm_nvdata_t *emm_data, const char *hplmn, const char *msin,
int ehplmn_count);
int write_emm_data(const char *directory, int user_id, emm_nvdata_t *emm_data); int write_emm_data(const char *directory, int user_id, emm_nvdata_t *emm_data);
int get_msin_parity(const char * msin, const char *mcc, const char *mnc); int get_msin_parity(const char * msin, const char *mcc, const char *mnc);
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#include "utils.h" #include "utils.h"
#include "conf_emm.h" #include "conf_emm.h"
#include "fs.h" #include "fs.h"
#include "conf_usim.h"
#include "conf2uedata.h" #include "conf2uedata.h"
#include "conf_usim.h"
int parse_ue_sim_param(config_setting_t *ue_setting, int user_id, usim_data_conf_t *u) { int parse_ue_sim_param(config_setting_t *ue_setting, int user_id, usim_data_conf_t *u) {
int rc = EXIT_SUCCESS; int rc = EXIT_SUCCESS;
...@@ -40,7 +40,8 @@ int parse_ue_sim_param(config_setting_t *ue_setting, int user_id, usim_data_conf ...@@ -40,7 +40,8 @@ int parse_ue_sim_param(config_setting_t *ue_setting, int user_id, usim_data_conf
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data) { void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data,
const user_plmns_t *user_plmns) {
int hplmn_index = get_plmn_index(u->hplmn); int hplmn_index = get_plmn_index(u->hplmn);
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;
...@@ -96,9 +97,9 @@ void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data) { ...@@ -96,9 +97,9 @@ void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data) {
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 (fplmns.size > 0) { if (user_plmns->forbiddens.size > 0) {
for (int i = 0; i < fplmns.size; i++) { for (int i = 0; i < user_plmns->forbiddens.size; i++) {
usim_data->fplmn[i] = user_network_record_list[fplmns.items[i]].plmn; usim_data->fplmn[i] = user_network_record_list[user_plmns->forbiddens.items[i]].plmn;
} }
} }
...@@ -183,8 +184,8 @@ void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data) { ...@@ -183,8 +184,8 @@ void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data) {
/* /*
* PLMN Network Name and Operator PLMN List * PLMN Network Name and Operator PLMN List
*/ */
for (int i = 0; i < oplmns.size; i++) { for (int i = 0; i < user_plmns->operators.size; i++) {
network_record_t record = user_network_record_list[oplmns.items[i]]; network_record_t record = user_network_record_list[user_plmns->operators.items[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,
...@@ -198,8 +199,8 @@ void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data) { ...@@ -198,8 +199,8 @@ void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data) {
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 (oplmns.size < USIM_OPL_MAX) { if (user_plmns->operators.size < USIM_OPL_MAX) {
for (int i = oplmns.size; i < USIM_OPL_MAX; i++) { for (int i = user_plmns->operators.size; 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));
} }
} }
...@@ -207,11 +208,11 @@ void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data) { ...@@ -207,11 +208,11 @@ void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data) {
/* /*
* List of Equivalent HPLMNs * List of Equivalent HPLMNs
*/ */
for (int i = 0; i < ehplmns.size; i++) { for (int i = 0; i < user_plmns->equivalents_home.size; i++) {
usim_data->ehplmn[i] = user_network_record_list[ehplmns.items[i]].plmn; usim_data->ehplmn[i] = user_network_record_list[user_plmns->equivalents_home.items[i]].plmn;
} }
if (ehplmns.size < USIM_EHPLMN_MAX) { if (user_plmns->equivalents_home.size < USIM_EHPLMN_MAX) {
for (int i = ehplmns.size; i < USIM_EHPLMN_MAX; i++) { for (int i = user_plmns->equivalents_home.size; i < USIM_EHPLMN_MAX; i++) {
memset(&usim_data->ehplmn[i], 0xff, sizeof(plmn_t)); memset(&usim_data->ehplmn[i], 0xff, sizeof(plmn_t));
} }
} }
...@@ -227,9 +228,9 @@ void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data) { ...@@ -227,9 +228,9 @@ void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data) {
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 (ucplmns.size > 0) { if (user_plmns->users_controlled.size > 0) {
for (int i = 0; i < ucplmns.size; i++) { for (int i = 0; i < user_plmns->users_controlled.size; i++) {
usim_data->plmn[i].plmn = user_network_record_list[ucplmns.items[i]].plmn; usim_data->plmn[i].plmn = user_network_record_list[user_plmns->users_controlled.items[i]].plmn;
} }
} }
...@@ -238,9 +239,9 @@ void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data) { ...@@ -238,9 +239,9 @@ void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data) {
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 (ocplmns.size > 0) { if (user_plmns->operators_controlled.size > 0) {
for (int i = 0; i < ocplmns.size; i++) { for (int i = 0; i < user_plmns->operators_controlled.size; i++) {
usim_data->oplmn[i].plmn = user_network_record_list[ocplmns.items[i]].plmn; usim_data->oplmn[i].plmn = user_network_record_list[user_plmns->operators_controlled.items[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);
} }
......
...@@ -40,6 +40,7 @@ typedef struct { ...@@ -40,6 +40,7 @@ typedef struct {
int parse_ue_sim_param(config_setting_t *ue_setting, int user_id, usim_data_conf_t *u); int parse_ue_sim_param(config_setting_t *ue_setting, int user_id, usim_data_conf_t *u);
int write_usim_data(const char *directory, int user_id, usim_data_t *usim_data); int write_usim_data(const char *directory, int user_id, usim_data_t *usim_data);
void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data); void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data,
const user_plmns_t *user_plmns);
#endif #endif
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