Commit 51c77535 authored by Frédéric Leroy's avatar Frédéric Leroy

refactor(conf2uedata): move networks function to conf_networks.[c|h]

parent 1b54e18a
......@@ -20,6 +20,7 @@ set(conf2uedata_SRC
${OPENAIR_DIR}/openair3/NAS/TOOLS/conf_emm.c
${OPENAIR_DIR}/openair3/NAS/TOOLS/conf_user_data.c
${OPENAIR_DIR}/openair3/NAS/TOOLS/conf_usim.c
${OPENAIR_DIR}/openair3/NAS/TOOLS/conf_network.c
${OPENAIR_DIR}/openair3/NAS/TOOLS/fs.c
${OPENAIR_DIR}/openair3/NAS/TOOLS/display.c
${OPENAIR_DIR}/openair3/NAS/UE/API/USIM/usim_api.c
......
......@@ -82,9 +82,8 @@ int parse_config_file(const char *output_dir, const char *conf_filename) {
return (EXIT_FAILURE);
}
rc = parse_plmns(all_plmn_setting, &networks);
if (rc == EXIT_FAILURE) {
return rc;
if ( parse_plmns(all_plmn_setting, &networks) == false ) {
return EXIT_FAILURE;
}
for (int i = 0; i < ue_nb; i++) {
......@@ -159,65 +158,6 @@ int get_config_from_file(const char *filename, config_t *config) {
}
int parse_plmn_param(config_setting_t *plmn_setting, plmn_conf_param_t *conf) {
int rc = 0;
rc = config_setting_lookup_string(plmn_setting, FULLNAME, &conf->fullname);
if (rc != 1) {
printf("Error on FULLNAME\n");
return EXIT_FAILURE;
}
rc = config_setting_lookup_string(plmn_setting, SHORTNAME, &conf->shortname);
if (rc != 1) {
printf("Error on SHORTNAME\n");
return EXIT_FAILURE;
}
rc = config_setting_lookup_string(plmn_setting, MNC, &conf->mnc);
if (rc != 1 || strlen(conf->mnc) > 3
|| strlen(conf->mnc) < 2) {
printf("Error ond MNC. Exiting\n");
return EXIT_FAILURE;
}
rc = config_setting_lookup_string(plmn_setting, MCC, &conf->mcc);
if (rc != 1 || strlen(conf->mcc) != 3) {
printf("Error on MCC\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int parse_plmns(config_setting_t *all_plmn_setting, networks_t *networks) {
config_setting_t *plmn_setting = NULL;
char plmn[10];
int rc = EXIT_SUCCESS;
int size = 0;
size = config_setting_length(all_plmn_setting);
networks->size = size;
networks->items = malloc(sizeof(network_t) * size);
for (int i = 0; i < size; i++) {
memset(&networks->items[i].record, 0xff, sizeof(network_record_t));
}
for (int i = 0; i < networks->size; i++) {
network_t *network = &networks->items[i];
sprintf(plmn, "%s%d", PLMN, i);
plmn_setting = config_setting_get_member(all_plmn_setting, plmn);
if (plmn_setting != NULL) {
rc = parse_plmn_param(plmn_setting, &network->conf);
if (rc == EXIT_FAILURE) {
return rc;
}
} else {
printf("Problem in PLMN%d. Exiting...\n", i);
return EXIT_FAILURE;
}
gen_network_record_from_conf(&network->conf, &network->record);
network->plmn = network->record.plmn;
}
return rc;
}
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) {
......@@ -285,55 +225,6 @@ int parse_Xplmn(config_setting_t *ue_setting, const char *section,
return EXIT_SUCCESS;
}
int get_plmn_index(const char * mccmnc, const networks_t networks) {
char mcc[4];
char mnc[strlen(mccmnc) - 2];
strncpy(mcc, mccmnc, 3);
mcc[3] = '\0';
strncpy(mnc, mccmnc + 3, 3);
mnc[strlen(mccmnc) - 3] = '\0';
for (int i = 0; i < networks.size; i++) {
if (strcmp(networks.items[i].conf.mcc, mcc) == 0) {
if (strcmp(networks.items[i].conf.mnc, mnc) == 0) {
return i;
}
}
}
return -1;
}
plmn_t make_plmn_from_conf(const plmn_conf_param_t *plmn_conf) {
plmn_t plmn;
char num[6];
memset(&plmn, 0xff, sizeof(plmn));
snprintf(num, 6, "%s%s", plmn_conf->mcc, plmn_conf->mnc);
plmn.MCCdigit2 = plmn_conf->mcc[1];
plmn.MCCdigit1 = plmn_conf->mcc[0];
plmn.MCCdigit3 = plmn_conf->mcc[2];
plmn.MNCdigit2 = plmn_conf->mnc[1];
plmn.MNCdigit1 = plmn_conf->mnc[0];
if (strlen(plmn_conf->mnc) > 2) {
plmn.MNCdigit3 = plmn_conf->mnc[2];
}
return plmn;
}
void gen_network_record_from_conf(const plmn_conf_param_t *conf, network_record_t *record) {
strcpy(record->fullname, conf->fullname);
strcpy(record->shortname, conf->shortname);
char num[6];
sprintf(num, "%s%s", conf->mcc, conf->mnc);
record->num = atoi(num);
record->plmn = make_plmn_from_conf(conf);
record->tac_end = 0xfffd;
record->tac_start = 0x0001;
}
/*
* Displays command line usage
*/
......
......@@ -4,16 +4,10 @@
#include <libconfig.h>
#include "usim_api.h"
#include "conf_network.h"
#define UE "UE"
#define PLMN "PLMN"
#define FULLNAME "FULLNAME"
#define SHORTNAME "SHORTNAME"
#define MNC "MNC"
#define MCC "MCC"
#define HPLMN "HPLMN"
#define UCPLMN "UCPLMN_LIST"
#define OPLMN "OPLMN_LIST"
......@@ -21,28 +15,6 @@
#define FPLMN "FPLMN_LIST"
#define EHPLMN "EHPLMN_LIST"
#define MIN_TAC 0x0000
#define MAX_TAC 0xFFFE
/*
* PLMN network operator record
*/
typedef struct {
unsigned int num;
plmn_t plmn;
char fullname[NET_FORMAT_LONG_SIZE + 1];
char shortname[NET_FORMAT_SHORT_SIZE + 1];
tac_t tac_start;
tac_t tac_end;
} network_record_t;
typedef struct {
const char *fullname;
const char *shortname;
const char *mnc;
const char *mcc;
} plmn_conf_param_t;
typedef struct {
int size;
int *items;
......@@ -56,26 +28,11 @@ typedef struct {
plmns_list equivalents_home;
} user_plmns_t;
typedef struct {
plmn_conf_param_t conf;
network_record_t record;
plmn_t plmn;
} network_t;
typedef struct {
int size;
network_t *items;
} networks_t;
int get_config_from_file(const char *filename, config_t *config);
int parse_config_file(const char *output_dir, const char *filename);
void _display_usage(void);
void gen_network_record_from_conf(const plmn_conf_param_t *conf, network_record_t *record);
int parse_plmn_param(config_setting_t *plmn_setting, plmn_conf_param_t *conf);
int parse_plmns(config_setting_t *all_plmn_setting, networks_t *plmns);
int get_plmn_index(const char * mccmnc, const networks_t networks);
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);
......
#include <stdlib.h>
#include <string.h>
#include "conf_network.h"
int get_plmn_index(const char * mccmnc, const networks_t networks) {
char mcc[4];
char mnc[strlen(mccmnc) - 2];
strncpy(mcc, mccmnc, 3);
mcc[3] = '\0';
strncpy(mnc, mccmnc + 3, 3);
mnc[strlen(mccmnc) - 3] = '\0';
for (int i = 0; i < networks.size; i++) {
if (strcmp(networks.items[i].conf.mcc, mcc) == 0) {
if (strcmp(networks.items[i].conf.mnc, mnc) == 0) {
return i;
}
}
}
return -1;
}
plmn_t make_plmn_from_conf(const plmn_conf_param_t *plmn_conf) {
plmn_t plmn;
char num[6];
memset(&plmn, 0xff, sizeof(plmn));
snprintf(num, 6, "%s%s", plmn_conf->mcc, plmn_conf->mnc);
plmn.MCCdigit2 = plmn_conf->mcc[1];
plmn.MCCdigit1 = plmn_conf->mcc[0];
plmn.MCCdigit3 = plmn_conf->mcc[2];
plmn.MNCdigit2 = plmn_conf->mnc[1];
plmn.MNCdigit1 = plmn_conf->mnc[0];
if (strlen(plmn_conf->mnc) > 2) {
plmn.MNCdigit3 = plmn_conf->mnc[2];
}
return plmn;
}
void gen_network_record_from_conf(const plmn_conf_param_t *conf, network_record_t *record) {
strcpy(record->fullname, conf->fullname);
strcpy(record->shortname, conf->shortname);
char num[6];
sprintf(num, "%s%s", conf->mcc, conf->mnc);
record->num = atoi(num);
record->plmn = make_plmn_from_conf(conf);
record->tac_end = 0xfffd;
record->tac_start = 0x0001;
}
bool parse_plmn_param(config_setting_t *plmn_setting, plmn_conf_param_t *conf) {
int rc = 0;
rc = config_setting_lookup_string(plmn_setting, FULLNAME, &conf->fullname);
if (rc != 1) {
printf("Error on FULLNAME\n");
return false;
}
rc = config_setting_lookup_string(plmn_setting, SHORTNAME, &conf->shortname);
if (rc != 1) {
printf("Error on SHORTNAME\n");
return false;
}
rc = config_setting_lookup_string(plmn_setting, MNC, &conf->mnc);
if (rc != 1 || strlen(conf->mnc) > 3
|| strlen(conf->mnc) < 2) {
printf("Error ond MNC. Exiting\n");
return false;
}
rc = config_setting_lookup_string(plmn_setting, MCC, &conf->mcc);
if (rc != 1 || strlen(conf->mcc) != 3) {
printf("Error on MCC\n");
return false;
}
return true;
}
bool parse_plmns(config_setting_t *all_plmn_setting, networks_t *networks) {
config_setting_t *plmn_setting = NULL;
char plmn[10];
int size = 0;
size = config_setting_length(all_plmn_setting);
networks->size = size;
networks->items = malloc(sizeof(network_t) * size);
for (int i = 0; i < size; i++) {
memset(&networks->items[i].record, 0xff, sizeof(network_record_t));
}
for (int i = 0; i < networks->size; i++) {
network_t *network = &networks->items[i];
sprintf(plmn, "%s%d", PLMN, i);
plmn_setting = config_setting_get_member(all_plmn_setting, plmn);
if (plmn_setting == NULL) {
printf("PLMN%d not fouund\n", i);
return false;
}
if ( parse_plmn_param(plmn_setting, &network->conf) == false ) {
return false;
}
gen_network_record_from_conf(&network->conf, &network->record);
network->plmn = network->record.plmn;
}
return true;
}
#ifndef _CONF_NETWORK_H
#define _CONF_NETWORK_H
#include <stdbool.h>
#include <libconfig.h>
#include "usim_api.h"
#define PLMN "PLMN"
#define FULLNAME "FULLNAME"
#define SHORTNAME "SHORTNAME"
#define MNC "MNC"
#define MCC "MCC"
#define MIN_TAC 0x0000
#define MAX_TAC 0xFFFE
/*
* PLMN network operator record
*/
typedef struct {
unsigned int num;
plmn_t plmn;
char fullname[NET_FORMAT_LONG_SIZE + 1];
char shortname[NET_FORMAT_SHORT_SIZE + 1];
tac_t tac_start;
tac_t tac_end;
} network_record_t;
typedef struct {
const char *fullname;
const char *shortname;
const char *mnc;
const char *mcc;
} plmn_conf_param_t;
typedef struct {
plmn_conf_param_t conf;
network_record_t record;
plmn_t plmn;
} network_t;
typedef struct {
int size;
network_t *items;
} networks_t;
bool parse_plmn_param(config_setting_t *plmn_setting, plmn_conf_param_t *conf);
bool parse_plmns(config_setting_t *all_plmn_setting, networks_t *plmns);
void gen_network_record_from_conf(const plmn_conf_param_t *conf, network_record_t *record);
int get_plmn_index(const char * mccmnc, const networks_t networks);
#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