Commit 17d15532 authored by Imad ALAWE's avatar Imad ALAWE Committed by FredericLeroy

feat: add conf2uedata tool for generating .*.nvram

This patch adds the conf2uedata tool for generating .ue.nvram* .ue.emm.nvram*
and .usim.nvram* files from a textual configuration file.

The configuration file define most usefull values like plmns, mnc, mcc, msin, K,
OPc for several users.
The files generated will always ends with a number corresponding to the user
entry in the configuration file.

This breaks oai5g because other script have not be updated for using
conf2uedata.
This breaks also the at_nas_ue command.

Examples of configuration files are in openair3/NAS/TOOLS/
parent c4707bd8
......@@ -82,7 +82,7 @@ Options
--eNB
Makes the LTE softmodem
--UE
Makes the UE specific parts (ue_ip, usim, nvram)
Makes the UE specific parts (ue_ip, usim, nvram) from the given configuration file
--RRH
Makes the RRH
-a | --agent
......@@ -145,6 +145,10 @@ Usage (Regular):
function main() {
local gen_nvram_path=$OPENAIR_DIR/targets/bin
local conf_nvram_path=$OPENAIR_DIR/openair3/NAS/TOOLS/ue_eurecom_test_sfr.conf
until [ -z "$1" ]
do
case "$1" in
......@@ -182,7 +186,16 @@ function main() {
--UE)
UE=1
echo_info "Will compile UE"
shift;;
shift
if test -n "$1"
then
[ -f "$1" ] || echo_fatal "file invalid for --UE"
conf_nvram_path=$(readlink -f "$1")
shift 1
fi;;
--UE-OUTPUT)
gen_nvram_path=$(readlink -f $2)
shift 2;;
--RRH)
RRH=1
echo_info "Will compile RRH"
......@@ -507,20 +520,12 @@ function main() {
cmake ..
compilations \
nas_sim_tools usim \
usim $dbin/usim
compilations \
nas_sim_tools nvram \
nvram $dbin/nvram
nas_sim_tools conf2uedata \
conf2uedata $dbin/conf2uedata
# generate USIM data
if [ -f $dbin/nvram ]; then
install_nas_tools $dbin $dconf
echo_info "Copying UE specific part to $DIR/$lte_build_dir/build"
cp -Rvf $dbin/.ue_emm.nvram $DIR/$lte_build_dir/build
cp -Rvf $dbin/.ue.nvram $DIR/$lte_build_dir/build
cp -Rvf $dbin/.usim.nvram $DIR/$lte_build_dir/build
if [ -f $dbin/conf2uedata ]; then
install_nas_tools $conf_nvram_path $gen_nvram_path
else
echo_warning "not generated UE NAS files: binaries not found"
fi
......@@ -637,15 +642,12 @@ function main() {
cd $DIR/nas_sim_tools/build
cmake ..
compilations \
nas_sim_tools usim \
usim $dbin/usim
compilations \
nas_sim_tools nvram \
nvram $dbin/nvram
nas_sim_tools conf2uedata \
conf2uedata $dbin/conf2uedata
# generate USIM data
if [ -f $dbin/nvram ]; then
install_nas_tools $dbin $dconf
if [ -f $dbin/conf2uedata ]; then
install_nas_tools $conf_nvram_path $gen_nvram_path
else
echo_warning "not generated UE NAS files: binaries not found"
fi
......
......@@ -2,25 +2,21 @@ cmake_minimum_required(VERSION 2.8)
project(NAS_SIM_TOOLS)
include(FindPkgConfig)
pkg_search_module(CONFIG libconfig REQUIRED)
include_directories(${CONFIG_INCLUDE_DIRS})
add_definitions(-std=gnu99)
ENABLE_LANGUAGE(C)
#Sends the -std=c99 flag to the gcc compiler
add_definitions(-std=c99)
add_definitions(-DNAS_UE)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} ${C_FLAGS_PROCESSOR} -Werror -Wall -Wstrict-prototypes -Wno-packed-bitfield-compat")
set(OPENAIR_DIR $ENV{OPENAIR_DIR})
set(OPENAIR1_DIR $ENV{OPENAIR_DIR}/openair1)
set(OPENAIR2_DIR $ENV{OPENAIR_DIR}/openair2)
set(OPENAIR3_DIR $ENV{OPENAIR_DIR}/openair3)
set(OPENAIR3_DIR $ENV{OPENAIR_DIR}/openair3)
set(OPENAIR_TARGETS $ENV{OPENAIR_DIR}/targets)
#set(EXECUTABLE_OUTPUT_PATH ${OPENAIR_DIR}/targets/bin)
# Add .h files for dependancies
set(usim_SRC
${OPENAIR_DIR}/openair3/NAS/TOOLS/usim_data.c
set(conf2uedata_SRC
${OPENAIR_DIR}/openair3/NAS/TOOLS/conf2uedata.c
${OPENAIR_DIR}/openair3/NAS/UE/API/USIM/usim_api.c
${OPENAIR_DIR}/openair3/NAS/UE/API/USIM/aka_functions.c
${OPENAIR_DIR}/openair3/NAS/COMMON/UTIL/memory.c
......@@ -29,8 +25,9 @@ set(usim_SRC
${OPENAIR_DIR}/openair3/NAS/COMMON/UTIL/TLVEncoder.c
${OPENAIR_DIR}/common/utils/utils.c
)
set(usim_HDR
${OPENAIR_DIR}/openair3/NAS/TOOLS/network.h
set(conf2uedata_HDR
${OPENAIR_DIR}/openair3/NAS/TOOLS/conf2uedata.h
${OPENAIR_DIR}/openair3/NAS/UE/API/USIM/usim_api.h
${OPENAIR_DIR}/openair3/NAS/UE/API/USIM/aka_functions.h
${OPENAIR_DIR}/openair3/NAS/COMMON/UTIL/memory.h
......@@ -39,37 +36,18 @@ set(usim_HDR
${OPENAIR_DIR}/openair3/NAS/COMMON/UTIL/TLVEncoder.h
${OPENAIR_DIR}/common/utils/utils.h
)
include_directories(
${OPENAIR_DIR}/common/utils
${OPENAIR_DIR}/openair3/NAS/UE
${OPENAIR_DIR}/openair3/NAS/COMMON
${OPENAIR_DIR}/openair3/NAS/UE/API/USER
${OPENAIR_DIR}/openair3/NAS/UE/API/USIM
${OPENAIR_DIR}/openair3/NAS/UE/EMM/
${OPENAIR_DIR}/openair3/NAS/UE/ESM/
${OPENAIR_DIR}/openair3/NAS/COMMON/IES/
${OPENAIR_DIR}/openair3/NAS/COMMON/UTIL
)
ADD_EXECUTABLE(usim ${usim_SRC} ${usim_HDR})
set(nvram_SRC
${OPENAIR_DIR}/openair3/NAS/TOOLS/ue_data.c
${OPENAIR_DIR}/openair3/NAS/COMMON/UTIL/memory.c
${OPENAIR_DIR}/openair3/NAS/COMMON/UTIL/nas_log.c
)
set(nvram_HDR
${OPENAIR_DIR}/openair3/NAS/UE/EMM/emmData.h
${OPENAIR_DIR}/openair3/NAS/COMMON/UTIL/memory.h
${OPENAIR_DIR}/openair3/NAS/COMMON/userDef.h
)
ADD_EXECUTABLE(nvram ${nvram_SRC} ${nvram_HDR})
#install (TARGETS usim DESTINATION ${EXECUTABLE_OUTPUT_PATH})
#install (TARGETS nvram DESTINATION ${EXECUTABLE_OUTPUT_PATH})
#install(CODE "EXECUTE_PROCESS (COMMAND ${OPENAIR_TARGETS}/bin/nvram --gen WORKING_DIRECTORY ${OPENAIR_TARGETS}/bin)")
#install(CODE "EXECUTE_PROCESS (COMMAND ${OPENAIR_TARGETS}/bin/usim --gen WORKING_DIRECTORY ${OPENAIR_TARGETS}/bin)")
ADD_EXECUTABLE(conf2uedata ${conf2uedata_SRC} ${conf2uedata_HDR})
target_link_libraries(conf2uedata ${CONFIG_LIBRARIES})
......@@ -450,24 +450,13 @@ install_asn1c_from_source(){
################################################
install_nas_tools() {
cd $1
if [ ! -f .ue.nvram ]; then
echo_success "generate .ue_emm.nvram .ue.nvram"
./nvram --gen
else
[ ./nvram -nt .ue.nvram -o ./nvram -nt .ue_emm.nvram ] && ./nvram --gen
fi
if [ ! -f .usim.nvram ]; then
echo_success "generate .usim.nvram"
./usim --gen
else
[ ./usim -nt .usim.nvram ] && ./usim --gen
if [ ! -f $2/§.ue.nvram -o ! -f $2/.usim.nvram ]; then
cd $OPENAIR_DIR/targets/bin
./conf2uedata -c $1 -o $2
echo_success "$1 $2"
fi
}
################################
# set_openair_env
###############################
......
......@@ -103,6 +103,30 @@ char* memory_get_path(const char* dirname, const char* filename)
return data_filename;
}
char* memory_get_path_from_ueid(const char* dirname, const char* filename, int ueid)
{
/* Get non-volatile data directory */
const char* path = getenv(dirname);
char buffer[2048];
if (path == NULL) {
path = getenv(DEFAULT_NAS_PATH);
}
if (path == NULL) {
LOG_TRACE(WARNING, "MEMORY - %s and %s environment variables are not defined trying local directory", dirname, DEFAULT_NAS_PATH);
path = ".";
}
/* Append non-volatile data file name */
if ( snprintf(buffer, sizeof(buffer), "%s/%s%d", path, filename, ueid) < 0 ) {
return NULL;
}
return strdup(buffer);
}
/****************************************************************************
** **
** Name: memory_read() **
......
......@@ -58,6 +58,8 @@ Description Memory access utilities
char* memory_get_path(const char* dirname, const char* filename);
char* memory_get_path_from_ueid(const char* dirname, const char* filename, int ueid);
int memory_read(const char* datafile, void* data, size_t size);
int memory_write(const char* datafile, const void* data, size_t size);
......
#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements. See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
# * the OAI Public License, Version 1.0 (the "License"); you may not use this file
# * except in compliance with the License.
# * You may obtain a copy of the License at
# *
# * http://www.openairinterface.org/?page_id=698
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# * contact@openairinterface.org
# */
export PROCESS = UE
ifndef PROJDIR
PROJDIR = $(PWD)/..
endif
include $(PROJDIR)/Makerules
include $(PROJDIR)/Makefile.inc
include $(PROJDIR)/../Makefile.tools
export LD_RUN_PATH = $(LIBDIR):$(LIBPROCESS)
LIBS = -luenas.a -lrt
INCLUDES = -I. -I$(INCDIR) -I$(UTILDIR) -I$(USIMAPIDIR) -I$(EMMDIR) -I$(ESMDIR) -I$(IESDIR)
#LIBSUTIL = $(LIBDIR)/$(LIBUTIL).a $(LIBDIR)/$(LIBUTIL).so
USIM_OBJ = usim_data.o
UE_OBJ = ue_data.o
USIM_TARGET = usim_data
UE_TARGET = ue_data
TARGETS = $(USIM_TARGET) $(UE_TARGET)
all: $(TARGETS)
#-DIMSI_USA_MNC_3DIGITS
%.o: %.c Makefile
$(CC) $(CFLAGS) -c $< -o $@
$(USIM_TARGET): $(USIM_OBJ) $(LIBSUTIL)
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) -lnettle -lcrypto -lm
@echo Replacing $@ to $(BINDIR)
@$(RM) $(BINDIR)/$@
@$(CP) $@ $(BINDIR)
$(UE_TARGET): $(UE_OBJ) $(LIBSUTIL)
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) -lnettle -lcrypto -lm
@echo Replacing $@ to $(BINDIR)
@$(RM) $(BINDIR)/$@
@$(CP) $@ $(BINDIR)
clean:
$(RM) $(OBJS) *.bak *~
veryclean: clean
$(RM) $(TARGETS)
veryveryclean: veryclean
$(RM) -Rf *.o $(PROJDIR)
$(RM) -Rf *.a $(PROJDIR)
depend:
makedepend -- ${CFLAGS} -- ${SRCS}
# DO NOT DELETE THIS LINE -- make depend depends on it.
This diff is collapsed.
#ifndef _CONF2UEDATA_H
#define _CONF2UEDATA_H
#include <libconfig.h>
#include "emmData.h"
#include "usim_api.h"
#include "userDef.h"
#include "memory.h"
#include "getopt.h"
#define USER "USER"
#define UE "UE"
#define SIM "SIM"
#define PLMN "PLMN"
#define FULLNAME "FULLNAME"
#define SHORTNAME "SHORTNAME"
#define MNC "MNC"
#define MCC "MCC"
#define MSIN "MSIN"
#define USIM_API_K "USIM_API_K"
#define OPC "OPC"
#define MSISDN "MSISDN"
#define UE_IMEI "IMEI"
#define MANUFACTURER "MANUFACTURER"
#define MODEL "MODEL"
#define PINCODE "PIN"
#define HPLMN "HPLMN"
#define UCPLMN "UCPLMN_LIST"
#define OPLMN "OPLMN_LIST"
#define OCPLMN "OCPLMN_LIST"
#define FPLMN "FPLMN_LIST"
#define EHPLMN "EHPLMN_LIST"
#define KSI USIM_KSI_NOT_AVAILABLE
#define PRINT_PLMN_DIGIT(d) if ((d) != 0xf) printf("%u", (d))
#define PRINT_PLMN(plmn) \
PRINT_PLMN_DIGIT((plmn).MCCdigit1); \
PRINT_PLMN_DIGIT((plmn).MCCdigit2); \
PRINT_PLMN_DIGIT((plmn).MCCdigit3); \
PRINT_PLMN_DIGIT((plmn).MNCdigit1); \
PRINT_PLMN_DIGIT((plmn).MNCdigit2); \
PRINT_PLMN_DIGIT((plmn).MNCdigit3)
#define KSI_ASME USIM_KSI_NOT_AVAILABLE
#define INT_ALGO USIM_INT_EIA1
#define ENC_ALGO USIM_ENC_EEA0
#define SECURITY_ALGORITHMS (ENC_ALGO | INT_ALGO)
#define OPC_SIZE 16
#define MIN_TAC 0x0000
#define MAX_TAC 0xFFFE
#define DEFAULT_TMSI 0x0000000D
#define DEFAULT_P_TMSI 0x0000000D
#define DEFAULT_M_TMSI 0x0000000D
#define DEFAULT_LAC 0xFFFE
#define DEFAULT_RAC 0x01
#define DEFAULT_TAC 0x0001
#define DEFAULT_MME_ID 0x0102
#define DEFAULT_MME_CODE 0x0F
#define PRINT_PLMN_DIGIT(d) if ((d) != 0xf) printf("%u", (d))
#define PRINT_PLMN(plmn) \
PRINT_PLMN_DIGIT((plmn).MCCdigit1); \
PRINT_PLMN_DIGIT((plmn).MCCdigit2); \
PRINT_PLMN_DIGIT((plmn).MCCdigit3); \
PRINT_PLMN_DIGIT((plmn).MNCdigit1); \
PRINT_PLMN_DIGIT((plmn).MNCdigit2); \
PRINT_PLMN_DIGIT((plmn).MNCdigit3)
/*
* 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;
const char options[]="c:o:h";
unsigned char parse_data=FALSE;
unsigned char print_data=FALSE;
unsigned char output=FALSE;
const char* conf_file = NULL;
const char* output_dir = NULL;
const char* imsi=NULL;
const char* msin=NULL;
const char* usim_api_k = NULL;
const char* msisdn = NULL;
const char* opc=NULL;
const char* hplmn=NULL;
int* ucplmn=NULL;
int* oplmn=NULL;
int* ocplmn=NULL;
int* fplmn=NULL;
int* ehplmn=NULL;
int hplmn_index =0;
int plmn_nb = 0;
int ucplmn_nb=0;
int oplmn_nb=0;
int ocplmn_nb=0;
int fplmn_nb=0;
int ehplmn_nb=0;
plmn_conf_param_t* user_plmn_list=NULL;
network_record_t* user_network_record_list = NULL;
void _display_usim_data(int user_id);
void _display_usage(void);
void gen_emm_data(int user_id) ;
void gen_usim_data(int user_id);
void fill_network_record_list(void);
int _luhn(const char* cc);
void _display_ue_data(int user_id);
void _display_emm_data(int user_id);
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_plmn_param(config_setting_t *plmn_setting, int index);
int parse_plmns(config_setting_t *all_plmn_setting);
int get_msin_parity(const char * msin);
int get_plmn_index(const char * mccmnc);
int parse_ue_plmn_param(config_setting_t *ue_setting, int user_id);
int fill_ucplmn(config_setting_t* setting, int use_id);
int fill_oplmn(config_setting_t* setting, int use_id);
int fill_ocplmn(config_setting_t* setting, int use_id);
int fill_fplmn(config_setting_t* setting, int use_id);
int fill_ehplmn(config_setting_t* setting, int use_id);
#endif // _CONF2UEDATA_H
This diff is collapsed.
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.0 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*****************************************************************************
Source ue_data.c
Version 0.1
Date 2012/11/02
Product UE data generator
Subsystem UE data generator main process
Author Frederic Maurel
Description Implements the utility used to generate data stored in the
UE's non-volatile memory device
*****************************************************************************/
#include "userDef.h"
#include "memory.h"
#include "emmData.h"
#include "network.h"
#include <stdio.h> // perror, printf, fprintf, snprintf
#include <stdlib.h> // exit, free
#include <string.h> // memset, strncpy
/****************************************************************************/
/**************** E X T E R N A L D E F I N I T I O N S ****************/
/****************************************************************************/
#define USER_IMEI "35611302209414"
#define USER_MANUFACTURER "EURECOM"
#define USER_MODEL "LTE Android PC"
//#define USER_MANUFACTURER "SAGEM"
//#define USER_MODEL "my225x"
#define USER_PIN "0000"
#define PRINT_PLMN_DIGIT(d) if ((d) != 0xf) printf("%u", (d))
#define PRINT_PLMN(plmn) \
PRINT_PLMN_DIGIT((plmn).MCCdigit1); \
PRINT_PLMN_DIGIT((plmn).MCCdigit2); \
PRINT_PLMN_DIGIT((plmn).MCCdigit3); \
PRINT_PLMN_DIGIT((plmn).MNCdigit1); \
PRINT_PLMN_DIGIT((plmn).MNCdigit2); \
PRINT_PLMN_DIGIT((plmn).MNCdigit3)
/****************************************************************************/
/******************* L O C A L D E F I N I T I O N S *******************/
/****************************************************************************/
static void _display_usage(const char* command);
static void _gen_user_data(user_nvdata_t* data);
static void _gen_emm_data(emm_nvdata_t* data);
static int _luhn(const char* cc);
static void _display_ue_data(const user_nvdata_t* data);
static void _display_emm_data(const emm_nvdata_t* data);
/****************************************************************************/
/****************** E X P O R T E D F U N C T I O N S ******************/
/****************************************************************************/
int main (int argc, const char* argv[])
{
int rc;
char* path;
user_nvdata_t user_data;
emm_nvdata_t emm_data;
unsigned char gen_data;
/*
* ----------------------------
* Read command line parameters
* ----------------------------
*/
if (argc != 2) {
fprintf(stderr, "Invalid parameter\n");
_display_usage(argv[0]);
exit(EXIT_FAILURE);
} else if ( (strcmp(argv[1], "--gen") == 0) ||
(strcmp(argv[1], "-g") == 0) ) {
/* Generate UE data files */
gen_data = TRUE;
} else if ( (strcmp(argv[1], "--print") == 0) ||
(strcmp(argv[1], "-p") == 0) ) {
/* Display content of UE data files */
gen_data = FALSE;
} else {
/* Display usage */
_display_usage(argv[0]);
exit(EXIT_SUCCESS);
}
/*
* ----------------------
* UE's non-volatile data
* ----------------------
*/
path = memory_get_path(USER_NVRAM_DIRNAME, USER_NVRAM_FILENAME);
if (path == NULL) {
perror("ERROR\t: memory_get_path() failed");
exit(EXIT_FAILURE);
}
if (gen_data) {
/*
* Initialize UE's non-volatile data
*/
memset(&user_data, 0, sizeof(user_nvdata_t));
_gen_user_data(&user_data);
/*
* Write UE's non-volatile data
*/
rc = memory_write(path, &user_data, sizeof(user_nvdata_t));
if (rc != RETURNok) {
perror("ERROR\t: memory_write() failed");
free(path);
exit(EXIT_FAILURE);
}
}
/*