Commit 86c8d0f9 authored by Frédéric Leroy's avatar Frédéric Leroy

refactor(conf2uedata): move plmns functions to conf_user_plmn.[c|h]

parent 51c77535
...@@ -21,6 +21,7 @@ set(conf2uedata_SRC ...@@ -21,6 +21,7 @@ set(conf2uedata_SRC
${OPENAIR_DIR}/openair3/NAS/TOOLS/conf_user_data.c ${OPENAIR_DIR}/openair3/NAS/TOOLS/conf_user_data.c
${OPENAIR_DIR}/openair3/NAS/TOOLS/conf_usim.c ${OPENAIR_DIR}/openair3/NAS/TOOLS/conf_usim.c
${OPENAIR_DIR}/openair3/NAS/TOOLS/conf_network.c ${OPENAIR_DIR}/openair3/NAS/TOOLS/conf_network.c
${OPENAIR_DIR}/openair3/NAS/TOOLS/conf_user_plmn.c
${OPENAIR_DIR}/openair3/NAS/TOOLS/fs.c ${OPENAIR_DIR}/openair3/NAS/TOOLS/fs.c
${OPENAIR_DIR}/openair3/NAS/TOOLS/display.c ${OPENAIR_DIR}/openair3/NAS/TOOLS/display.c
${OPENAIR_DIR}/openair3/NAS/UE/API/USIM/usim_api.c ${OPENAIR_DIR}/openair3/NAS/UE/API/USIM/usim_api.c
......
...@@ -105,8 +105,7 @@ int parse_config_file(const char *output_dir, const char *conf_filename) { ...@@ -105,8 +105,7 @@ int parse_config_file(const char *output_dir, const char *conf_filename) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
rc = parse_user_plmns_conf(ue_setting, i, &user_plmns, &usim_data_conf.hplmn, networks); if ( parse_user_plmns_conf(ue_setting, i, &user_plmns, &usim_data_conf.hplmn, networks) == false ) {
if (rc != EXIT_SUCCESS) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -130,6 +129,8 @@ int parse_config_file(const char *output_dir, const char *conf_filename) { ...@@ -130,6 +129,8 @@ int parse_config_file(const char *output_dir, const char *conf_filename) {
user_plmns.equivalents_home.size, networks); user_plmns.equivalents_home.size, networks);
write_emm_data(output_dir, i, &emm_data); write_emm_data(output_dir, i, &emm_data);
user_plmns_free(&user_plmns);
} }
free(networks.items); free(networks.items);
networks.size=0; networks.size=0;
...@@ -157,74 +158,6 @@ int get_config_from_file(const char *filename, config_t *config) { ...@@ -157,74 +158,6 @@ int get_config_from_file(const char *filename, config_t *config) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
int parse_user_plmns_conf(config_setting_t *ue_setting, int user_id,
user_plmns_t *user_plmns, const char **h,
const networks_t networks) {
int nb_errors = 0;
const char *hplmn;
if ( config_setting_lookup_string(ue_setting, HPLMN, h) != 1 ) {
printf("Check HPLMN section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
}
hplmn = *h;
if (get_plmn_index(hplmn, networks) == -1) {
printf("HPLMN for UE%d is not defined in PLMN section. Exiting\n",
user_id);
return EXIT_FAILURE;
}
if ( parse_Xplmn(ue_setting, UCPLMN, user_id, &user_plmns->users_controlled, networks) == EXIT_FAILURE )
nb_errors++;
if ( parse_Xplmn(ue_setting, OPLMN, user_id, &user_plmns->operators, networks) == EXIT_FAILURE )
nb_errors++;
if ( parse_Xplmn(ue_setting, OCPLMN, user_id, &user_plmns->operators_controlled, networks) == EXIT_FAILURE )
nb_errors++;
if ( parse_Xplmn(ue_setting, FPLMN, user_id, &user_plmns->forbiddens, networks) == EXIT_FAILURE )
nb_errors++;
if ( parse_Xplmn(ue_setting, EHPLMN, user_id, &user_plmns->equivalents_home, networks) == EXIT_FAILURE )
nb_errors++;
if ( nb_errors > 0 )
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
int parse_Xplmn(config_setting_t *ue_setting, const char *section,
int user_id, plmns_list *plmns, const networks_t networks) {
int rc;
int item_count;
config_setting_t *setting;
setting = config_setting_get_member(ue_setting, section);
if (setting == NULL) {
printf("Check %s section for UE%d. Exiting\n", section, user_id);
return EXIT_FAILURE;
}
item_count = config_setting_length(setting);
int *datas = malloc(item_count * sizeof(int));
for (int i = 0; i < item_count; i++) {
const char *mccmnc = config_setting_get_string_elem(setting, i);
if (mccmnc == NULL) {
printf("Check %s section for UE%d. Exiting\n", section, user_id);
return EXIT_FAILURE;
}
rc = get_plmn_index(mccmnc, networks);
if (rc == -1) {
printf("The PLMN %s is not defined in PLMN section. Exiting...\n",
mccmnc);
return EXIT_FAILURE;
}
datas[i] = rc;
}
plmns->size = item_count;
plmns->items = datas;
return EXIT_SUCCESS;
}
/* /*
* Displays command line usage * Displays command line usage
*/ */
......
...@@ -8,36 +8,9 @@ ...@@ -8,36 +8,9 @@
#define UE "UE" #define UE "UE"
#define HPLMN "HPLMN"
#define UCPLMN "UCPLMN_LIST"
#define OPLMN "OPLMN_LIST"
#define OCPLMN "OCPLMN_LIST"
#define FPLMN "FPLMN_LIST"
#define EHPLMN "EHPLMN_LIST"
typedef struct {
int size;
int *items;
} plmns_list;
typedef struct {
plmns_list users_controlled;
plmns_list operators;
plmns_list operators_controlled;
plmns_list forbiddens;
plmns_list equivalents_home;
} user_plmns_t;
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 *output_dir, const char *filename); int parse_config_file(const char *output_dir, const char *filename);
void _display_usage(void); void _display_usage(void);
int parse_user_plmns_conf(config_setting_t *ue_setting, int user_id,
user_plmns_t *user_plmns, const char **h,
const networks_t networks);
int parse_Xplmn(config_setting_t *ue_setting, const char *section,
int user_id, plmns_list *plmns, const networks_t networks);
#endif // _CONF2UEDATA_H #endif // _CONF2UEDATA_H
#include <stdlib.h>
#include <string.h>
#include "conf_user_plmn.h"
bool parse_user_plmns_conf(config_setting_t *ue_setting, int user_id,
user_plmns_t *user_plmns, const char **h,
const networks_t networks) {
int nb_errors = 0;
const char *hplmn;
if ( config_setting_lookup_string(ue_setting, HPLMN, h) != 1 ) {
printf("Check HPLMN section for UE%d. Exiting\n", user_id);
return false;
}
hplmn = *h;
if (get_plmn_index(hplmn, networks) == -1) {
printf("HPLMN for UE%d is not defined in PLMN section. Exiting\n",
user_id);
return false;
}
if ( parse_Xplmn(ue_setting, UCPLMN, user_id, &user_plmns->users_controlled, networks) == false )
nb_errors++;
if ( parse_Xplmn(ue_setting, OPLMN, user_id, &user_plmns->operators, networks) == false )
nb_errors++;
if ( parse_Xplmn(ue_setting, OCPLMN, user_id, &user_plmns->operators_controlled, networks) == false )
nb_errors++;
if ( parse_Xplmn(ue_setting, FPLMN, user_id, &user_plmns->forbiddens, networks) == false )
nb_errors++;
if ( parse_Xplmn(ue_setting, EHPLMN, user_id, &user_plmns->equivalents_home, networks) == false )
nb_errors++;
if ( nb_errors > 0 )
return false;
return true;
}
bool parse_Xplmn(config_setting_t *ue_setting, const char *section,
int user_id, plmns_list *plmns, const networks_t networks) {
int rc;
int item_count;
config_setting_t *setting;
setting = config_setting_get_member(ue_setting, section);
if (setting == NULL) {
printf("Check %s section for UE%d. Exiting\n", section, user_id);
return false;
}
item_count = config_setting_length(setting);
int *datas = malloc(item_count * sizeof(int));
for (int i = 0; i < item_count; i++) {
const char *mccmnc = config_setting_get_string_elem(setting, i);
if (mccmnc == NULL) {
printf("Check %s section for UE%d. Exiting\n", section, user_id);
free(datas);
return false;
}
rc = get_plmn_index(mccmnc, networks);
if (rc == -1) {
printf("The PLMN %s is not defined in PLMN section. Exiting...\n",
mccmnc);
free(datas);
return false;
}
datas[i] = rc;
}
plmns->size = item_count;
plmns->items = datas;
return true;
}
void user_plmns_free(user_plmns_t *user_plmns) {
free(user_plmns->users_controlled.items);
free(user_plmns->operators.items);
free(user_plmns->operators_controlled.items);
free(user_plmns->forbiddens.items);
free(user_plmns->equivalents_home.items);
memset(user_plmns, 0, sizeof(user_plmns_t));
}
#ifndef _CONF_USER_H
#define _CONF_USER_H
#include <stdbool.h>
#include <libconfig.h>
#include "conf_network.h"
#define HPLMN "HPLMN"
#define UCPLMN "UCPLMN_LIST"
#define OPLMN "OPLMN_LIST"
#define OCPLMN "OCPLMN_LIST"
#define FPLMN "FPLMN_LIST"
#define EHPLMN "EHPLMN_LIST"
typedef struct {
int size;
int *items;
} plmns_list;
typedef struct {
plmns_list users_controlled;
plmns_list operators;
plmns_list operators_controlled;
plmns_list forbiddens;
plmns_list equivalents_home;
} user_plmns_t;
bool parse_user_plmns_conf(config_setting_t *ue_setting, int user_id,
user_plmns_t *user_plmns, const char **h,
const networks_t networks);
bool parse_Xplmn(config_setting_t *ue_setting, const char *section,
int user_id, plmns_list *plmns, const networks_t networks);
void user_plmns_free(user_plmns_t *user_plmns);
#endif
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <libconfig.h> #include <libconfig.h>
#include "usim_api.h" #include "usim_api.h"
#include "conf_user_plmn.h"
#define SIM "SIM" #define SIM "SIM"
#define MSIN "MSIN" #define MSIN "MSIN"
......
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