Commit f3616257 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

apply simple format

parent 5d4921e4
......@@ -4,7 +4,7 @@ AMF =
INSTANCE_ID = 10;
PID_DIRECTORY = "/var/run";
######################################################################## NG SETUP RESPONSE IEs ############################################################
AMF_NAME = "bupt-amf";
AMF_NAME = "amf";
GUAMI:{MCC = "208"; MNC = "95"; RegionID = "128"; AMFSetID = "1"; AMFPointer = "1"}
ServedGUAMIList = (
{MCC = "208"; MNC = "95"; RegionID = "10"; AMFSetID = "1"; AMFPointer = "0"}, #48bits <MCC><MNC><RegionID><AMFSetID><AMFPointer>
......
This diff is collapsed.
......@@ -45,53 +45,39 @@ using namespace std;
static uint32_t amf_app_ue_ngap_id_generator = 1;
namespace amf_application{
namespace amf_application {
#define TASK_AMF_APP_PERIODIC_STATISTICS (0)
class amf_app{
public:
class amf_app {
public:
explicit amf_app(const amf_config &amf_cfg);
amf_app(amf_app const&) = delete;
void operator=(amf_app const&) = delete;
void allRegistredModulesInit(const amf_modules & modules);
void operator=(amf_app const&) = delete;
void allRegistredModulesInit(const amf_modules &modules);
long generate_amf_ue_ngap_id();
public://itti handlers
void handle_itti_message(itti_nas_signalling_establishment_request & itti_msg);
void handle_itti_message(itti_n1n2_message_transfer_request & itti_msg);
public://context management
//itti handlers
void handle_itti_message(itti_nas_signalling_establishment_request &itti_msg);
void handle_itti_message(itti_n1n2_message_transfer_request &itti_msg);
//context management
std::map<long, std::shared_ptr<ue_context>> amf_ue_ngap_id2ue_ctx;
mutable std::shared_mutex m_amf_ue_ngap_id2ue_ctx;
std::map<std::string, std::shared_ptr<ue_context>> ue_ctx_key;
mutable std::shared_mutex m_ue_ctx_key;
bool is_amf_ue_id_2_ue_context(const long & amf_ue_ngap_id) const;
std::shared_ptr<ue_context> amf_ue_id_2_ue_context(const long & amf_ue_ngap_id) const;
void set_amf_ue_ngap_id_2_ue_context(const long & amf_ue_ngap_id, std::shared_ptr<ue_context> uc);
bool is_ran_amf_id_2_ue_context(const string & ue_context_key) const;
std::shared_ptr<ue_context> ran_amf_id_2_ue_context(const string & ue_context_key) const;
void set_ran_amf_id_2_ue_context(const string & ue_context_key, std::shared_ptr<ue_context> uc);
public:/*** SMF Client response handlers ****/
bool is_amf_ue_id_2_ue_context(const long &amf_ue_ngap_id) const;
std::shared_ptr<ue_context> amf_ue_id_2_ue_context(const long &amf_ue_ngap_id) const;
void set_amf_ue_ngap_id_2_ue_context(const long &amf_ue_ngap_id, std::shared_ptr<ue_context> uc);
bool is_ran_amf_id_2_ue_context(const string &ue_context_key) const;
std::shared_ptr<ue_context> ran_amf_id_2_ue_context(const string &ue_context_key) const;
void set_ran_amf_id_2_ue_context(const string &ue_context_key, std::shared_ptr<ue_context> uc);
// SMF Client response handlers
void handle_post_sm_context_response_error_400();
public:
bool generate_5g_guti(uint32_t ranid, long amfid, string &mcc, string &mnc, uint32_t& tmsi);
//others
bool generate_5g_guti(uint32_t ranid, long amfid, string &mcc, string &mnc, uint32_t &tmsi);
};
}
#endif
This diff is collapsed.
......@@ -95,28 +95,27 @@
#define AMF_CONFIG_STRING_NAS_SUPPORTED_INTEGRITY_ALGORITHM_LIST "ORDERED_SUPPORTED_INTEGRITY_ALGORITHM_LIST"
#define AMF_CONFIG_STRING_NAS_SUPPORTED_CIPHERING_ALGORITHM_LIST "ORDERED_SUPPORTED_CIPHERING_ALGORITHM_LIST"
using namespace libconfig;
using namespace std;
namespace config{
namespace config {
typedef struct{
typedef struct {
string mysql_server;
string mysql_user;
string mysql_pass;
string mysql_db;
string operator_key;
string random;
}auth_conf;
} auth_conf;
typedef struct interface_cfg_s {
std::string if_name;
struct in_addr addr4;
struct in_addr network4;
std::string if_name;
struct in_addr addr4;
struct in_addr network4;
struct in6_addr addr6;
unsigned int mtu;
unsigned int port;
unsigned int mtu;
unsigned int port;
util::thread_sched_params thread_rd_sched_params;
} interface_cfg_t;
......@@ -128,62 +127,62 @@ typedef struct itti_cfg_s {
util::thread_sched_params async_cmd_sched_params;
} itti_cfg_t;
typedef struct guami_s{
typedef struct guami_s {
string mcc;
string mnc;
string regionID;
string AmfSetID;
string AmfPointer;
}guami_t;
} guami_t;
typedef struct slice_s{
typedef struct slice_s {
string sST;
string sD;
}slice_t;
} slice_t;
typedef struct plmn_support_item_s{
typedef struct plmn_support_item_s {
string mcc;
string mnc;
uint32_t tac;
vector<slice_t> slice_list;
}plmn_item_t;
} plmn_item_t;
typedef struct{
uint8_t prefered_integrity_algorithm[8];
uint8_t prefered_ciphering_algorithm[8];
}nas_conf_t;
typedef struct {
uint8_t prefered_integrity_algorithm[8];
uint8_t prefered_ciphering_algorithm[8];
} nas_conf_t;
typedef struct{
typedef struct {
int id;
string ipv4;
string port;
string version;
bool selected;
}smf_inst_t;
} smf_inst_t;
class amf_config{
public:
class amf_config {
public:
amf_config();
~amf_config();
int load(const std::string &config_file);
int load_interface(const Setting& if_cfg, interface_cfg_t & cfg);
int load_thread_sched_params(const libconfig::Setting& thread_sched_params_cfg, util::thread_sched_params& cfg);
int load_interface(const Setting &if_cfg, interface_cfg_t &cfg);
int load_thread_sched_params(const libconfig::Setting &thread_sched_params_cfg, util::thread_sched_params &cfg);
void display();
public:
unsigned int instance;
string pid_dir;
interface_cfg_t n2;
itti_cfg_t itti;
unsigned int statistics_interval;
string AMF_Name;
guami_t guami;
vector<guami_t> guami_list;
unsigned int relativeAMFCapacity;
vector<plmn_item_t> plmn_list;
string is_emergency_support;
auth_conf auth_para;
nas_conf_t nas_cfg;
vector<smf_inst_t> smf_pool;
public:
unsigned int instance;
string pid_dir;
interface_cfg_t n2;
itti_cfg_t itti;
unsigned int statistics_interval;
string AMF_Name;
guami_t guami;
vector<guami_t> guami_list;
unsigned int relativeAMFCapacity;
vector<plmn_item_t> plmn_list;
string is_emergency_support;
auth_conf auth_para;
nas_conf_t nas_cfg;
vector<smf_inst_t> smf_pool;
};
}
......
......@@ -32,56 +32,57 @@
#include <string>
using namespace std;
namespace config {
namespace config{
int amf_modules::load(const std::string &config_file){
cout<<endl;
Logger::amf_app().debug("Load amf module configuration file(%s)",config_file.c_str());
Config cfg;
try{
//------------------------------------------------------------------------------
int amf_modules::load(const std::string &config_file) {
cout << endl;
Logger::amf_app().debug("Load amf module configuration file(%s)", config_file.c_str());
Config cfg;
try {
cfg.readFile(config_file.c_str());
}catch(const FileIOException &fioex){
} catch (const FileIOException &fioex) {
Logger::amf_app().error("I/O error while reading file %s - %s", config_file.c_str(), fioex.what());
throw;
}catch(const ParseException &pex){
} catch (const ParseException &pex) {
Logger::amf_app().error("Parse error at %s:%d - %s", pex.getFile(), pex.getLine(), pex.getError());
throw;
}
const Setting &root = cfg.getRoot();
try{
const Setting& modules = root[MODULES_CONFIG_STRING_AMF_MODULES];
}catch(const SettingNotFoundException &nfex){
try {
const Setting &modules = root[MODULES_CONFIG_STRING_AMF_MODULES];
} catch (const SettingNotFoundException &nfex) {
Logger::amf_app().error("%s : %s", nfex.what(), nfex.getPath());
return -1;
}
const Setting &modules = root[MODULES_CONFIG_STRING_AMF_MODULES];
const Setting &msg = modules[MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE];
int count = msg.getLength();
for(int i=0; i< count; i++){
const Setting & item = msg[i];
for (int i = 0; i < count; i++) {
const Setting &item = msg[i];
std::string typeOfMessage;
int procedure_code;
item.lookupValue(MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_NAME, msgName);
item.lookupValue(MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_PROCEDURECODE, procedure_code);
item.lookupValue(MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_TYPEOFMSG, typeOfMessage);
procedureCode = (Ngap_ProcedureCode_t)procedure_code;
if(!(typeOfMessage.compare("initialMessage"))){
procedureCode = (Ngap_ProcedureCode_t) procedure_code;
if (!(typeOfMessage.compare("initialMessage"))) {
typeOfMsg = Ngap_NGAP_PDU_PR_initiatingMessage;
}else if(!(typeOfMessage.compare("successfuloutcome"))){
} else if (!(typeOfMessage.compare("successfuloutcome"))) {
typeOfMsg = Ngap_NGAP_PDU_PR_successfulOutcome;
}else if(!(typeOfMessage.compare("unsuccessfuloutcome"))){
} else if (!(typeOfMessage.compare("unsuccessfuloutcome"))) {
typeOfMsg = Ngap_NGAP_PDU_PR_unsuccessfulOutcome;
}else{
} else {
Logger::config().error("wrong NGAP message configuration");
}
}
}
void amf_modules::display(){
Logger::config().info( "======= AMF Registered Modules =======");
Logger::config().info( "NGAP Message Modules:");
Logger::config().info( "- %s([%d,%d])\n", msgName.c_str(), procedureCode, typeOfMsg);
//------------------------------------------------------------------------------
void amf_modules::display() {
Logger::config().info("======= AMF Registered Modules =======");
Logger::config().info("NGAP Message Modules:");
Logger::config().info("- %s([%d,%d])\n", msgName.c_str(), procedureCode, typeOfMsg);
}
}
......@@ -44,26 +44,24 @@
#include "Ngap_ProcedureCode.h"
#include "Ngap_NGAP-PDU.h"
#define MODULES_CONFIG_STRING_AMF_MODULES "MODULES"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE "NGAP_MESSAGE"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_NAME "MSG_NAME"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_PROCEDURECODE "ProcedureCode"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_TYPEOFMSG "TypeOfMessage"
using namespace libconfig;
namespace config{
namespace config {
class amf_modules{
public:
class amf_modules {
public:
int load(const std::string &config_file);
void display();
void makeModulesAlive();
private:
std::string msgName;//vector to store more msgs
Ngap_NGAP_PDU_PR typeOfMsg;
void makeModulesAlive();
private:
std::string msgName; //vector to store more msgs
Ngap_NGAP_PDU_PR typeOfMsg;
Ngap_ProcedureCode_t procedureCode;
// NGSetupRequestMsg *ngSetupRequest;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -51,108 +51,99 @@
#include "mysql_db.hpp"
namespace amf_application{
namespace amf_application {
#define NAS_MESSAGE_DOWNLINK 1
#define NAS_MESSAGE_UPLINK 0
typedef enum{
typedef enum {
PlainNasMsg = 0x0,
IntegrityProtected = 0x1,
IntegrityProtectedAndCiphered = 0x2,
IntegrityProtectedWithNew5GNASSecurityContext = 0x3,
IntegrityProtectedAndCipheredWithNew5GNASSecurityContext = 0x4,
}SecurityHeaderType;
} SecurityHeaderType;
class amf_n1{
public:
class amf_n1 {
public:
amf_n1();
~amf_n1();
void handle_itti_message(itti_uplink_nas_data_ind&);
void handle_itti_message(itti_downlink_nas_transfer & itti_msg);
public: // nas message decode
void handle_itti_message(itti_downlink_nas_transfer &itti_msg);
public: // nas message decode
void nas_signalling_establishment_request_handle(SecurityHeaderType type, std::shared_ptr<nas_context> nc, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg, std::string snn, uint8_t ulCount);
void uplink_nas_msg_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg);
bool check_security_header_type(SecurityHeaderType & type, uint8_t *buffer);
bool check_security_header_type(SecurityHeaderType &type, uint8_t *buffer);
public:
std::map<long, std::shared_ptr<nas_context>> amfueid2nas_context; // amf ue ngap id
public:
std::map<long, std::shared_ptr<nas_context>> amfueid2nas_context; // amf ue ngap id
std::map<string, std::shared_ptr<nas_context>> imsi2nas_context;
std::map<std::string, long> supi2amfId;
std::map<std::string, uint32_t> supi2ranId;
std::map<std::string, std::shared_ptr<nas_context>> guti2nas_context;
mutable std::shared_mutex m_guti2nas_context;
bool is_guti_2_nas_context(const std::string & guti) const;
std::shared_ptr<nas_context> guti_2_nas_context(const std::string & guti) const;
void set_guti_2_nas_context(const std::string & guti, std::shared_ptr<nas_context>nc);
bool is_guti_2_nas_context(const std::string &guti) const;
std::shared_ptr<nas_context> guti_2_nas_context(const std::string &guti) const;
void set_guti_2_nas_context(const std::string &guti, std::shared_ptr<nas_context> nc);
mutable std::shared_mutex m_amfueid2nas_context;
bool is_amf_ue_id_2_nas_context(const long & amf_ue_ngap_id) const;
std::shared_ptr<nas_context> amf_ue_id_2_nas_context(const long & amf_ue_ngap_id) const;
void set_amf_ue_ngap_id_2_nas_context(const long & amf_ue_ngap_id, std::shared_ptr<nas_context> nc);
bool is_amf_ue_id_2_nas_context(const long &amf_ue_ngap_id) const;
std::shared_ptr<nas_context> amf_ue_id_2_nas_context(const long &amf_ue_ngap_id) const;
void set_amf_ue_ngap_id_2_nas_context(const long &amf_ue_ngap_id, std::shared_ptr<nas_context> nc);
database_t *db_desc;
private://nas message handlers
private: //nas message handlers
void ue_initiate_de_registration_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas);
void registration_request_handle(bool isNasSig, std::shared_ptr<nas_context>nc, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, std::string snn, bstring reg);
void registration_request_handle(bool isNasSig, std::shared_ptr<nas_context> nc, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, std::string snn, bstring reg);
void authentication_response_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg);
void authentication_failure_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg);
void security_mode_complete_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas_msg);
void security_mode_reject_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas_msg);
void ul_nas_transport_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas);
void sha256(unsigned char * message, int msg_len, unsigned char * output);
void sha256(unsigned char *message, int msg_len, unsigned char *output);
void service_request_handle(bool isNasSig, std::shared_ptr<nas_context> nc, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas);
private://authentication vector
private: //authentication vector
bool generate_authentication_vector();
private:
void itti_send_dl_nas_buffer_to_task_n2(bstring & b, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id);
private://response message
private:
void itti_send_dl_nas_buffer_to_task_n2(bstring &b, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id);
private: //response message
void response_registration_reject_msg(uint8_t cause_value, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id);
public://procedures
void run_registration_procedure(std::shared_ptr<nas_context>&nc);
public: //procedures
void run_registration_procedure(std::shared_ptr<nas_context> &nc);
void run_initial_registration_procedure();
void run_mobility_registration_update_procedure(std::shared_ptr<nas_context>nc);
public://authentication
bool auth_vectors_generator(std::shared_ptr<nas_context>&nc);
bool authentication_vectors_generator_in_ausf(std::shared_ptr<nas_context>&nc);
bool authentication_vectors_generator_in_udm(std::shared_ptr<nas_context>&nc);
public://mysql handlers in mysql_db.cpp
void run_mobility_registration_update_procedure(std::shared_ptr<nas_context> nc);
public: //authentication
bool auth_vectors_generator(std::shared_ptr<nas_context> &nc);
bool authentication_vectors_generator_in_ausf(std::shared_ptr<nas_context> &nc);
bool authentication_vectors_generator_in_udm(std::shared_ptr<nas_context> &nc);
public: //mysql handlers in mysql_db.cpp
bool get_mysql_auth_info(std::string imsi, mysql_auth_info_t &resp);
void mysql_push_rand_sqn(std::string imsi, uint8_t *rand_p, uint8_t *sqn);
void mysql_increment_sqn(std::string imsi);
bool connect_to_mysql();
void generate_random(uint8_t *random_p, ssize_t length);
void generate_5g_he_av_in_udm(const uint8_t opc[16], std::string imsi, uint8_t key[16], uint8_t sqn[6], std::string serving_network, _5G_HE_AV_t &vector);
void test_generate_5g_he_av_in_udm(const uint8_t opc[16], uint8_t key[16], uint8_t sqnak[6], std::string serving_network, _5G_HE_AV_t &vector);
void test_generate_5g_he_av_in_udm(const uint8_t opc[16], uint8_t key[16], uint8_t sqnak[6], std::string serving_network, _5G_HE_AV_t &vector);
void handle_auth_vector_successful_result(std::shared_ptr<nas_context> nc);
bool start_authentication_procedure(std::shared_ptr<nas_context> nc, int vindex, uint8_t ngksi);
bool check_nas_common_procedure_on_going(std::shared_ptr<nas_context> nc);
int security_select_algorithms(uint8_t nea, uint8_t nia, uint8_t &amf_nea, uint8_t &amf_nia);
bool start_security_mode_control_procedure(std::shared_ptr<nas_context>nc);
void encode_nas_message_protected(nas_secu_ctx * nsc, bool is_secu_ctx_new, uint8_t security_header_type, uint8_t direction, uint8_t *input_nas_buf, int input_nas_len, bstring & encrypted_nas);
bool start_security_mode_control_procedure(std::shared_ptr<nas_context> nc);
void encode_nas_message_protected(nas_secu_ctx *nsc, bool is_secu_ctx_new, uint8_t security_header_type, uint8_t direction, uint8_t *input_nas_buf, int input_nas_len, bstring &encrypted_nas);
bool nas_message_integrity_protected(nas_secu_ctx *nsc, uint8_t direction, uint8_t *input_nas, int input_nas_len, uint32_t &mac);
bool nas_message_cipher_protected(nas_secu_ctx *nsc, uint8_t direction, bstring input_nas, bstring &output_nas);
public:
public:
void dump_nas_message(uint8_t *buf, int len);
public:
public:
void ue_authentication_simulator(uint8_t *rand, uint8_t *autn);
void annex_a_4_33501(uint8_t ck[16], uint8_t ik[16], uint8_t *input, uint8_t rand[16], std::string serving_network, uint8_t *output);
public:
public:
void send_itti_to_smf_services_consumer(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, uint8_t request_type, uint8_t pdu_session_id, bstring dnn, bstring sm_msg);
public:
public:
void update_ue_information_statics(ue_infos &ueItem, const string connStatus, const string registerStatus, uint32_t ranid, uint32_t amfid, string imsi, string guti, string mcc, string mnc, uint32_t cellId);
};
}
#endif
This diff is collapsed.
......@@ -35,68 +35,32 @@
#include <string>
using namespace std;
namespace amf_application{
namespace amf_application {
class amf_n11{
public:
class amf_n11 {
public:
amf_n11();
~amf_n11();
public:
void handle_itti_message(itti_smf_services_consumer &);
void handle_itti_message(itti_smf_services_consumer&);
void handle_pdu_session_initial_request(string supi, std::shared_ptr<pdu_session_context> psc, string smf_addr, bstring sm_msg, string dnn);
void handle_itti_message(itti_pdu_session_resource_setup_response &itti_msg);
void handle_itti_message(itti_nsmf_pdusession_update_sm_context &itti_msg);
public:
std::map<string, std::shared_ptr<pdu_session_context>> supi2pdu; // amf ue ngap id
std::map<string, std::shared_ptr<pdu_session_context>> supi2pdu; // amf ue ngap id
mutable std::shared_mutex m_supi2pdu;
bool is_supi_to_pdu_ctx(const string &supi) const;
std::shared_ptr<pdu_session_context> supi_to_pdu_ctx(const string & supi) const;
std::shared_ptr<pdu_session_context> supi_to_pdu_ctx(const string &supi) const;
void set_supi_to_pdu_ctx(const string &supi, std::shared_ptr<pdu_session_context> psc);
public:
std::map<uint8_t, string> pduid2supi;
public:
bool smf_selection_from_configuration(string & smf_addr);
bool smf_selection_from_context(string & smf_addr);
public:
bool smf_selection_from_configuration(string &smf_addr);
bool smf_selection_from_context(string &smf_addr);
void handle_post_sm_context_response_error_400();
void handle_post_sm_context_response_error(long code, string cause, bstring n1sm, string supi, uint8_t pdu_session_id);
public:
void curl_http_client(string remoteUri, string jsonData, string n1SmMsg, string n2SmMsg, string supi, uint8_t pdu_session_id);
};
}
#endif
This diff is collapsed.
......@@ -36,7 +36,7 @@
namespace amf_application{
class amf_n2 : public ngap::ngap_app{
public:
public:
amf_n2(const string &address, const uint16_t port_num);
~amf_n2();
//void handle_receive(bstring payload, sctp_assoc_id_t assoc_id, sctp_stream_id_t stream, sctp_stream_id_t instreams, sctp_stream_id_t outstreams);
......@@ -50,7 +50,7 @@ public:
void handle_itti_message(itti_ue_context_release_request &itti_msg);
void handle_itti_message(itti_ue_radio_capability_indication &itti_msg);
bool verifyPlmn(vector<SupportedItem_t> list);
private:
private:
std::map<uint32_t, std::shared_ptr<ue_ngap_context>> ranid2uecontext;// ran ue ngap id
mutable std::shared_mutex m_ranid2uecontext;
......@@ -59,13 +59,6 @@ private:
void set_ran_ue_ngap_id_2_ue_ngap_context(const uint32_t & ran_ue_ngap_id, std::shared_ptr<ue_ngap_context> unc);
};
}
......@@ -81,6 +74,4 @@ private:
#endif
......@@ -31,36 +31,41 @@
#include <iostream>
using namespace std;
void statistics::display(){
cout<<endl;
//------------------------------------------------------------------------------
void statistics::display() {
cout << endl;
//Logger::amf_app().info("--------------------------------------------------");
//Logger::amf_app().info("| connected gNBs | connected UEs | registred UEs |");
//Logger::amf_app().info("| connected gNBs | connected UEs | registered UEs |");
//Logger::amf_app().info("--------------------------------------------------");
//Logger::amf_app().info("| %d | %d | %d |",gNB_connected,UE_connected,UE_registred);
//Logger::amf_app().info("--------------------------------------------------");
Logger::amf_app().info("|--------------------------------------------------------------------------------------------------------------------|");
Logger::amf_app().info("-----------------------------------------------------------------------------------------------------------------");
Logger::amf_app().info("|-----------------------------------------------------------------------------------------------------------------|");
Logger::amf_app().info("|----------------------------------------------------gNBs' information--------------------------------------------|");
for(int i=0; i<gnbs.size(); i++){
Logger::amf_app().info("[index %d][connected][GlobalID: 0x%x][gnb name: %s][Tracking Area: plmn(%s), tac(%d)]", i+1, gnbs[i].gnb_id, gnbs[i].gnb_name.c_str(), (gnbs[i].mcc+gnbs[i].mnc).c_str(), gnbs[i].tac);
for (int i = 0; i < gnbs.size(); i++) {
Logger::amf_app().info("[index %d][connected][GlobalID: 0x%x][gnb name: %s][Tracking Area: plmn(%s), tac(%d)]", i + 1, gnbs[i].gnb_id, gnbs[i].gnb_name.c_str(), (gnbs[i].mcc + gnbs[i].mnc).c_str(), gnbs[i].tac);
}
Logger::amf_app().info("-----------------------------------------------------------------------------------------------------------------"); cout<<endl;
Logger::amf_app().info("-----------------------------------------------------------------------------------------------------------------");
Logger::amf_app().info("");
Logger::amf_app().info("|----------------------------------------------------------------------------------------------------------------|");
Logger::amf_app().info("|----------------------------------------------------UEs' information--------------------------------------------|");
for(int i=0; i<ues.size();i++){
Logger::amf_app().info("[index %d][%s][%s][imsi %s][guti %s]", i+1, ues[i].connStatus.c_str(), ues[i].registerStatus.c_str(), ues[i].imsi.c_str(), ues[i].guti.c_str());
for (int i = 0; i < ues.size(); i++) {
Logger::amf_app().info("[index %d][%s][%s][imsi %s][guti %s]", i + 1, ues[i].connStatus.c_str(), ues[i].registerStatus.c_str(), ues[i].imsi.c_str(), ues[i].guti.c_str());
Logger::amf_app().info("Current ran_ue_ngap_id[%d]; Current amf_ue_ngap_id[%d]", ues[i].ranid, ues[i].amfid);
Logger::amf_app().info("Location[NrCgi][PLMN(%s), cellID(%d)]", (ues[i].mcc+ues[i].mnc).c_str(), ues[i].cellId); cout<<endl;
Logger::amf_app().info("Location[NrCgi][PLMN(%s), cellID(%d)]", (ues[i].mcc + ues[i].mnc).c_str(), ues[i].cellId);
Logger::amf_app().info("");
}
Logger::amf_app().info("-----------------------------------------------------------------------------------------------------------------");
Logger::amf_app().info("|--------------------------------------------------------------------------------------------------------------------|"); cout<<endl;
Logger::amf_app().info("|--------------------------------------------------------------------------------------------------------------------|");
Logger::amf_app().info("");
}
statistics::statistics(){
//------------------------------------------------------------------------------
statistics::statistics() {
gNB_connected = 0;
UE_connected = 0;
UE_registred = 0;
}
statistics::~statistics(){}
//------------------------------------------------------------------------------
statistics::~statistics() {
}
......@@ -37,47 +37,40 @@
using namespace std;
typedef struct{
typedef struct {
uint32_t gnb_id;
string mcc;
string mnc;
string gnb_name;
uint32_t tac;
//long nrCellId;
}gnb_infos;
} gnb_infos;
typedef struct{
string connStatus;
string registerStatus;
typedef struct {
string connStatus;
string registerStatus;
uint32_t ranid;
long amfid;
string imsi;
string guti;
string mcc;
string mnc;
long amfid;
string imsi;
string guti;
string mcc;
string mnc;
uint32_t cellId;
}ue_infos;
} ue_infos;
class statistics{
public:
class statistics {
public:
void display();
statistics();
~statistics();
public:
uint32_t gNB_connected;
uint32_t UE_connected;
uint32_t UE_registred;
public:
uint32_t gNB_connected;
uint32_t UE_connected;
uint32_t UE_registred;
//uint32_t system_pdu_sessions;
vector<gnb_infos> gnbs;
vector<ue_infos> ues;
vector<gnb_infos> gnbs;
vector<ue_infos> ues;
};
#endif
......@@ -34,151 +34,155 @@ using namespace config;
extern amf_config amf_cfg;
bool amf_n1::get_mysql_auth_info(std::string imsi, mysql_auth_info_t &resp){//openair-cn/tree/v0.5.0/src/oai_hss/db/db_connector.c
//------------------------------------------------------------------------------
bool amf_n1::get_mysql_auth_info(std::string imsi, mysql_auth_info_t &resp) { //openair-cn/tree/v0.5.0/src/oai_hss/db/db_connector.c
MYSQL_RES *res;
MYSQL_ROW row;
MYSQL_ROW row;
std::string query;
if(!db_desc->db_conn){
if (!db_desc->db_conn) {
Logger::amf_n1().error("Cannot connect to mysql db");
return false;
}
query = "SELECT `key`,`sqn`,`rand`,`OPc` FROM `users` WHERE `users`.`imsi`='"+imsi+"' ";
pthread_mutex_lock (&db_desc->db_cs_mutex);
if(mysql_query(db_desc->db_conn, query.c_str())){
pthread_mutex_unlock (&db_desc->db_cs_mutex);
Logger::amf_n1().error("Query execution failed: %s\n", mysql_error (db_desc->db_conn));
query = "SELECT `key`,`sqn`,`rand`,`OPc` FROM `users` WHERE `users`.`imsi`='" + imsi + "' ";
pthread_mutex_lock(&db_desc->db_cs_mutex);
if (mysql_query(db_desc->db_conn, query.c_str())) {
pthread_mutex_unlock(&db_desc->db_cs_mutex);
Logger::amf_n1().error("Query execution failed: %s\n", mysql_error(db_desc->db_conn));
return false;
}
res = mysql_store_result (db_desc->db_conn);
pthread_mutex_unlock (&db_desc->db_cs_mutex);
if(!res){
res = mysql_store_result(db_desc->db_conn);
pthread_mutex_unlock(&db_desc->db_cs_mutex);
if (!res) {
Logger::amf_n1().error("data fetched from mysql is not present");
return false;
}
if(row = mysql_fetch_row(res)){
if(row[0] == NULL || row[1] == NULL || row[2] == NULL || row[3] == NULL){
if (row = mysql_fetch_row(res)) {
if (row[0] == NULL || row[1] == NULL || row[2] == NULL || row[3] == NULL) {
Logger::amf_n1().error("row data failed");
return false;
}
memcpy (resp.key, row[0], KEY_LENGTH);
uint64_t sqn = 0;
sqn = atoll(row[1]);
resp.sqn[0] = (sqn & (255UL << 40)) >> 40;
resp.sqn[1] = (sqn & (255UL << 32)) >> 32;
resp.sqn[2] = (sqn & (255UL << 24)) >> 24;
resp.sqn[3] = (sqn & (255UL << 16)) >> 16;
resp.sqn[4] = (sqn & (255UL << 8)) >> 8;
resp.sqn[5] = (sqn & 0xff);
memcpy (resp.rand, row[2], RAND_LENGTH);
memcpy (resp.opc, row[3], KEY_LENGTH);
}
mysql_free_result (res);
memcpy(resp.key, row[0], KEY_LENGTH);
uint64_t sqn = 0;
sqn = atoll(row[1]);
resp.sqn[0] = (sqn & (255UL << 40)) >> 40;
resp.sqn[1] = (sqn & (255UL << 32)) >> 32;
resp.sqn[2] = (sqn & (255UL << 24)) >> 24;
resp.sqn[3] = (sqn & (255UL << 16)) >> 16;
resp.sqn[4] = (sqn & (255UL << 8)) >> 8;
resp.sqn[5] = (sqn & 0xff);
memcpy(resp.rand, row[2], RAND_LENGTH);
memcpy(resp.opc, row[3], KEY_LENGTH);
}
mysql_free_result(res);
return true;
}
bool amf_n1::connect_to_mysql(){
//------------------------------------------------------------------------------
bool amf_n1::connect_to_mysql() {
const int mysql_reconnect_val = 1;
db_desc = (database_t*)calloc(1, sizeof(database_t));
if(!db_desc){
db_desc = (database_t*) calloc(1, sizeof(database_t));
if (!db_desc) {
Logger::amf_n1().error("An error occurs when calloc");
return false;
}
pthread_mutex_init (&db_desc->db_cs_mutex, NULL);
pthread_mutex_init(&db_desc->db_cs_mutex, NULL);
db_desc->server = amf_cfg.auth_para.mysql_server;
db_desc->user = amf_cfg.auth_para.mysql_user;
db_desc->password = amf_cfg.auth_para.mysql_pass;
db_desc->database = amf_cfg.auth_para.mysql_db;
db_desc->db_conn = mysql_init (NULL);
mysql_options (db_desc->db_conn, MYSQL_OPT_RECONNECT, &mysql_reconnect_val);
if (!mysql_real_connect (db_desc->db_conn, db_desc->server.c_str(), db_desc->user.c_str(), db_desc->password.c_str(), db_desc->database.c_str(), 0, NULL, 0)) {
Logger::amf_n1().error("An error occured while connecting to db: %s", mysql_error (db_desc->db_conn));
db_desc->db_conn = mysql_init(NULL);
mysql_options(db_desc->db_conn, MYSQL_OPT_RECONNECT, &mysql_reconnect_val);
if (!mysql_real_connect(db_desc->db_conn, db_desc->server.c_str(), db_desc->user.c_str(), db_desc->password.c_str(), db_desc->database.c_str(), 0, NULL, 0)) {
Logger::amf_n1().error("An error occurred while connecting to db: %s", mysql_error(db_desc->db_conn));
mysql_thread_end();
return false;
}
mysql_set_server_option (db_desc->db_conn, MYSQL_OPTION_MULTI_STATEMENTS_ON);
mysql_set_server_option(db_desc->db_conn, MYSQL_OPTION_MULTI_STATEMENTS_ON);
return true;
}
void amf_n1::mysql_push_rand_sqn(std::string imsi, uint8_t *rand_p, uint8_t *sqn){
int status = 0;
MYSQL_RES *res;
char query[1000];
int query_length = 0;
uint64_t sqn_decimal = 0;
if(!db_desc->db_conn){
//------------------------------------------------------------------------------
void amf_n1::mysql_push_rand_sqn(std::string imsi, uint8_t *rand_p, uint8_t *sqn) {
int status = 0;
MYSQL_RES *res;
char query[1000];
int query_length = 0;
uint64_t sqn_decimal = 0;
if (!db_desc->db_conn) {
Logger::amf_n1().error("Cannot connect to mysql");
return;
}
if(!sqn || !rand_p){
if (!sqn || !rand_p) {
Logger::amf_n1().error("need sqn and rand");
return;
}
sqn_decimal = ((uint64_t) sqn[0] << 40) | ((uint64_t) sqn[1] << 32) | ((uint64_t) sqn[2] << 24) | (sqn[3] << 16) | (sqn[4] << 8) | sqn[5];
query_length = sprintf (query, "UPDATE `users` SET `rand`=UNHEX('");
query_length = sprintf(query, "UPDATE `users` SET `rand`=UNHEX('");
for (int i = 0; i < RAND_LENGTH; i++) {
query_length += sprintf (&query[query_length], "%02x", rand_p[i]);
query_length += sprintf(&query[query_length], "%02x", rand_p[i]);
}
query_length += sprintf (&query[query_length], "'),`sqn`=%" PRIu64, sqn_decimal);
query_length += sprintf (&query[query_length], " WHERE `users`.`imsi`='%s'", imsi.c_str());
pthread_mutex_lock (&db_desc->db_cs_mutex);
if (mysql_query (db_desc->db_conn, query)) {
pthread_mutex_unlock (&db_desc->db_cs_mutex);
Logger::amf_n1().error("Query execution failed: %s", mysql_error (db_desc->db_conn));
query_length += sprintf(&query[query_length], " WHERE `users`.`imsi`='%s'", imsi.c_str());
pthread_mutex_lock(&db_desc->db_cs_mutex);
if (mysql_query(db_desc->db_conn, query)) {
pthread_mutex_unlock(&db_desc->db_cs_mutex);
Logger::amf_n1().error("Query execution failed: %s", mysql_error(db_desc->db_conn));
return;
}
do{
res = mysql_store_result (db_desc->db_conn);
if(res){
mysql_free_result (res);
}else{
if(mysql_field_count (db_desc->db_conn) == 0) {
Logger::amf_n1().error("%lld rows affected", mysql_affected_rows (db_desc->db_conn));
}else{ /* some error occurred */
do {
res = mysql_store_result(db_desc->db_conn);
if (res) {
mysql_free_result(res);
} else {
if (mysql_field_count(db_desc->db_conn) == 0) {
Logger::amf_n1().error("%lld rows affected", mysql_affected_rows(db_desc->db_conn));
} else { /* some error occurred */
Logger::amf_n1().error("Could not retrieve result set");
break;
}
}
if ((status = mysql_next_result (db_desc->db_conn)) > 0)
if ((status = mysql_next_result(db_desc->db_conn)) > 0)
Logger::amf_n1().error("Could not execute statement");
}while(status == 0);
pthread_mutex_unlock (&db_desc->db_cs_mutex);
} while (status == 0);
pthread_mutex_unlock(&db_desc->db_cs_mutex);
return;
}
void amf_n1::mysql_increment_sqn(std::string imsi){
int status;
MYSQL_RES *res;
char query[1000];
//------------------------------------------------------------------------------
void amf_n1::mysql_increment_sqn(std::string imsi) {
int status;
MYSQL_RES *res;
char query[1000];
if (db_desc->db_conn == NULL) {
Logger::amf_n1().error("Cannot connect to mysql");
return;
}
sprintf (query, "UPDATE `users` SET `sqn` = `sqn` + 32 WHERE `users`.`imsi`='%s'", imsi.c_str());
sprintf(query, "UPDATE `users` SET `sqn` = `sqn` + 32 WHERE `users`.`imsi`='%s'", imsi.c_str());
pthread_mutex_lock(&db_desc->db_cs_mutex);
if (mysql_query (db_desc->db_conn, query)) {
pthread_mutex_unlock (&db_desc->db_cs_mutex);
Logger::amf_n1().error("Query execution failed: %s", mysql_error (db_desc->db_conn));
if (mysql_query(db_desc->db_conn, query)) {
pthread_mutex_unlock(&db_desc->db_cs_mutex);
Logger::amf_n1().error("Query execution failed: %s", mysql_error(db_desc->db_conn));
return;
}
do{
res = mysql_store_result (db_desc->db_conn);
do {
res = mysql_store_result(db_desc->db_conn);
if (res) {
mysql_free_result (res);
} else {
if (mysql_field_count (db_desc->db_conn) == 0) {
Logger::amf_n1().error("%lld rows affected", mysql_affected_rows (db_desc->db_conn));
} else {
mysql_free_result(res);
} else {
if (mysql_field_count(db_desc->db_conn) == 0) {
Logger::amf_n1().error("%lld rows affected", mysql_affected_rows(db_desc->db_conn));
} else {
Logger::amf_n1().error("Could not retrieve result set");
break;
}
}
if ((status = mysql_next_result (db_desc->db_conn)) > 0)
if ((status = mysql_next_result(db_desc->db_conn)) > 0)
Logger::amf_n1().error("Could not execute statement");
}while(status == 0);
pthread_mutex_unlock (&db_desc->db_cs_mutex);
} while (status == 0);
pthread_mutex_unlock(&db_desc->db_cs_mutex);
return;
}
......@@ -38,15 +38,15 @@
#define KEY_LENGTH (16)
#define SQN_LENGTH (6)
#define RAND_LENGTH (16)
typedef struct{
typedef struct {
uint8_t key[KEY_LENGTH];
uint8_t sqn[SQN_LENGTH];
uint8_t opc[KEY_LENGTH];
uint8_t rand[RAND_LENGTH];
}mysql_auth_info_t;
} mysql_auth_info_t;
typedef struct {
/* The mysql reference connector object */
//mysql reference connector object
MYSQL *db_conn;
std::string server;
std::string user;
......
......@@ -33,35 +33,37 @@
#include <string>
using namespace std;
void print_buffer(const string app, const string commit, uint8_t *buf, int len){
if(!app.compare("amf_app"))
//------------------------------------------------------------------------------
void print_buffer(const string app, const string commit, uint8_t *buf, int len) {
if (!app.compare("amf_app"))
Logger::amf_app().debug(commit.c_str());
if(!app.compare("amf_n1"))
if (!app.compare("amf_n1"))
Logger::amf_n1().debug(commit.c_str());
if(!app.compare("amf_server"))
if (!app.compare("amf_server"))
Logger::amf_server().debug(commit.c_str());
if(!app.compare("amf_n11"))
if (!app.compare("amf_n11"))
Logger::amf_n11().debug(commit.c_str());
for(int i=0; i<len; i++)
printf("%x ",buf[i]);
printf("\n");
for (int i = 0; i < len; i++)
printf("%x ", buf[i]);
printf("\n");
}
void hexStr2Byte(const char* src, unsigned char *dest, int len){
//------------------------------------------------------------------------------
void hexStr2Byte(const char *src, unsigned char *dest, int len) {
short i;
unsigned char hBy, lBy;
for(i=0; i<len; i+=2){
for (i = 0; i < len; i += 2) {
hBy = toupper(src[i]);
lBy = toupper(src[i+1]);
if(hBy > 0x39)
lBy = toupper(src[i + 1]);
if (hBy > 0x39)
hBy -= 0x37;
else
hBy -= 0x30;
if(lBy > 0x39)
if (lBy > 0x39)
lBy -= 0x37;
else
lBy -= 0x30;
dest[i/2] = (hBy<<4) | lBy;
dest[i / 2] = (hBy << 4) | lBy;
}
}
......
......@@ -20,10 +20,10 @@
*/
/*! \file conversions.cpp
\brief
\author Sebastien ROUX
\company Eurecom
*/
\brief
\author Sebastien ROUX
\company Eurecom
*/
#include "conversions.hpp"
#include <stdlib.h>
......@@ -33,57 +33,35 @@
#include <inttypes.h>
#include <arpa/inet.h>
static const char hex_to_ascii_table[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
};
static const signed char ascii_to_hex_table[0x100] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
void conv::hexa_to_ascii (
uint8_t * from,
char *to,
size_t length)
{
size_t i;
static const char hex_to_ascii_table[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', };
static const signed char ascii_to_hex_table[0x100] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
//------------------------------------------------------------------------------
void conv::hexa_to_ascii(uint8_t *from, char *to, size_t length) {
size_t i;
for (i = 0; i < length; i++) {
uint8_t upper = (from[i] & 0xf0) >> 4;
uint8_t lower = from[i] & 0x0f;
uint8_t upper = (from[i] & 0xf0) >> 4;
uint8_t lower = from[i] & 0x0f;
to[2 * i] = hex_to_ascii_table[upper];
to[2 * i + 1] = hex_to_ascii_table[lower];
}
}
int conv::ascii_to_hex (
uint8_t * dst,
const char *h)
{
const unsigned char *hex = (const unsigned char *)h;
unsigned i = 0;
//------------------------------------------------------------------------------
int conv::ascii_to_hex(uint8_t *dst, const char *h) {
const unsigned char *hex = (const unsigned char*) h;
unsigned i = 0;
for (;;) {
int high,
low;
int high, low;
while (*hex && isspace (*hex))
while (*hex && isspace(*hex))
hex++;
if (!*hex)
......@@ -94,7 +72,7 @@ int conv::ascii_to_hex (
if (high < 0)
return 0;
while (*hex && isspace (*hex))
while (*hex && isspace(*hex))
hex++;
if (!*hex)
......@@ -109,63 +87,57 @@ int conv::ascii_to_hex (
}
}
//------------------------------------------------------------------------------
std::string conv::mccToString(const uint8_t digit1, const uint8_t digit2, const uint8_t digit3)
{
std::string s = {};
uint16_t mcc16 = digit1*100+digit2*10+digit3;
std::string conv::mccToString(const uint8_t digit1, const uint8_t digit2, const uint8_t digit3) {
std::string s = { };
uint16_t mcc16 = digit1 * 100 + digit2 * 10 + digit3;
//s.append(std::to_string(digit1)).append(std::to_string(digit2)).append(std::to_string(digit3));
s.append(std::to_string(mcc16));
return s;
}
//------------------------------------------------------------------------------
std::string conv::mncToString(const uint8_t digit1, const uint8_t digit2, const uint8_t digit3)
{
std::string s = {};
std::string conv::mncToString(const uint8_t digit1, const uint8_t digit2, const uint8_t digit3) {
std::string s = { };
uint16_t mcc16 = 0;
if (digit3 == 0x0F) {
mcc16 = digit1*10+digit2;
mcc16 = digit1 * 10 + digit2;
} else {
mcc16 = digit1*100+digit2*10+digit3;
mcc16 = digit1 * 100 + digit2 * 10 + digit3;
}
s.append(std::to_string(mcc16));
return s;
}
//------------------------------------------------------------------------------
struct in_addr conv::fromString(const std::string addr4)
{
unsigned char buf[sizeof(struct in6_addr)] = {};
struct in_addr conv::fromString(const std::string addr4) {
unsigned char buf[sizeof(struct in6_addr)] = { };
int s = inet_pton(AF_INET, addr4.c_str(), buf);
struct in_addr * ia = (struct in_addr *)buf;
struct in_addr *ia = (struct in_addr*) buf;
return *ia;
}
//------------------------------------------------------------------------------
std::string conv::toString(const struct in_addr& inaddr)
{
std::string s = {};
char str[INET6_ADDRSTRLEN] = {};
if (inet_ntop(AF_INET, (const void *)&inaddr, str, INET6_ADDRSTRLEN) == NULL) {
std::string conv::toString(const struct in_addr &inaddr) {
std::string s = { };
char str[INET6_ADDRSTRLEN] = { };
if (inet_ntop(AF_INET, (const void*) &inaddr, str, INET6_ADDRSTRLEN) == NULL) {
s.append("Error in_addr");
} else {
s.append(str);
}
return s;
}
//------------------------------------------------------------------------------
std::string conv::toString(const struct in6_addr& in6addr)
{
std::string s = {};
char str[INET6_ADDRSTRLEN] = {};
if (inet_ntop(AF_INET6, (const void *)&in6addr, str, INET6_ADDRSTRLEN) == nullptr) {
std::string conv::toString(const struct in6_addr &in6addr) {
std::string s = { };
char str[INET6_ADDRSTRLEN] = { };
if (inet_ntop(AF_INET6, (const void*) &in6addr, str, INET6_ADDRSTRLEN) == nullptr) {
s.append("Error in6_addr");
} else {
s.append(str);
}
return s;
}
......@@ -20,11 +20,11 @@
*/
/*! \file conversions.hpp
\brief
\author Sebastien ROUX, Lionel Gauthier
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
\brief
\author Sebastien ROUX, Lionel Gauthier
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
#ifndef FILE_CONVERSIONS_HPP_SEEN
#define FILE_CONVERSIONS_HPP_SEEN
......@@ -32,7 +32,6 @@
#include <string>
#include <netinet/in.h>
/* Used to format an uint32_t containing an ipv4 address */
#define IN_ADDR_FMT "%u.%u.%u.%u"
#define PRI_IN_ADDR(aDDRESS) \
......@@ -44,15 +43,14 @@
#define IPV4_ADDR_DISPLAY_8(aDDRESS) \
(aDDRESS)[0], (aDDRESS)[1], (aDDRESS)[2], (aDDRESS)[3]
class conv {
public:
static void hexa_to_ascii(uint8_t *from, char *to, size_t length);
static int ascii_to_hex(uint8_t *dst, const char *h);
static struct in_addr fromString(const std::string addr4);
static std::string toString(const struct in_addr& inaddr);
static std::string toString(const struct in6_addr& in6addr);
static std::string mccToString(const uint8_t digit1, const uint8_t digit2, const uint8_t digit3);
static std::string mncToString(const uint8_t digit1, const uint8_t digit2, const uint8_t digit3);
public:
static void hexa_to_ascii(uint8_t *from, char *to, size_t length);
static int ascii_to_hex(uint8_t *dst, const char *h);
static struct in_addr fromString(const std::string addr4);
static std::string toString(const struct in_addr &inaddr);
static std::string toString(const struct in6_addr &in6addr);
static std::string mccToString(const uint8_t digit1, const uint8_t digit2, const uint8_t digit3);
static std::string mncToString(const uint8_t digit1, const uint8_t digit2, const uint8_t digit3);
};
#endif /* FILE_CONVERSIONS_HPP_SEEN */
......@@ -20,11 +20,11 @@
*/
/*! \file endpoint.hpp
\brief
\author Lionel Gauthier
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
\brief
\author Lionel Gauthier
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
#ifndef FILE_ENDPOINT_HPP_SEEN
#define FILE_ENDPOINT_HPP_SEEN
......@@ -37,25 +37,39 @@
#include <string.h>
class endpoint {
public :
public:
struct sockaddr_storage addr_storage;
socklen_t addr_storage_len;
endpoint() : addr_storage(), addr_storage_len(sizeof(struct sockaddr_storage)) {};
endpoint(const endpoint& e) : addr_storage(e.addr_storage), addr_storage_len(e.addr_storage_len) {};
endpoint(const struct sockaddr_storage& addr, const socklen_t len) : addr_storage(addr), addr_storage_len(len) {};
endpoint(const struct in_addr& addr, const uint16_t port)
{
struct sockaddr_in * addr_in = (struct sockaddr_in *)&addr_storage;
socklen_t addr_storage_len;
endpoint()
:
addr_storage(),
addr_storage_len(sizeof(struct sockaddr_storage)) {
}
;
endpoint(const endpoint &e)
:
addr_storage(e.addr_storage),
addr_storage_len(e.addr_storage_len) {
}
;
endpoint(const struct sockaddr_storage &addr, const socklen_t len)
:
addr_storage(addr),
addr_storage_len(len) {
}
;
endpoint(const struct in_addr &addr, const uint16_t port) {
struct sockaddr_in *addr_in = (struct sockaddr_in*) &addr_storage;
addr_in->sin_family = AF_INET;
addr_in->sin_port = htons(port);
addr_in->sin_addr.s_addr = addr.s_addr;
addr_storage_len = sizeof(struct sockaddr_in);
};
}
;
endpoint(const struct in6_addr& addr6, const uint16_t port)
{
struct sockaddr_in6 * addr_in6 = (struct sockaddr_in6 *)&addr_storage;
endpoint(const struct in6_addr &addr6, const uint16_t port) {
struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6*) &addr_storage;
addr_in6->sin6_family = AF_INET6;
addr_in6->sin6_port = htons(port);
addr_in6->sin6_flowinfo = 0;
......@@ -63,30 +77,27 @@ public :
addr_in6->sin6_scope_id = 0;
addr_storage_len = sizeof(struct sockaddr_in6);
};
}
;
uint16_t port() const
{
return ntohs(((struct sockaddr_in *)&addr_storage)->sin_port);
uint16_t port() const {
return ntohs(((struct sockaddr_in*) &addr_storage)->sin_port);
}
sa_family_t family() const
{
sa_family_t family() const {
return addr_storage.ss_family;
}
std::string toString() const
{
std::string toString() const {
std::string str;
if (addr_storage.ss_family == AF_INET) {
struct sockaddr_in * addr_in = (struct sockaddr_in *)&addr_storage;
struct sockaddr_in *addr_in = (struct sockaddr_in*) &addr_storage;
str.append(conv::toString(addr_in->sin_addr));
str.append(":").append(std::to_string(ntohs(addr_in->sin_port)));
}
else if (addr_storage.ss_family == AF_INET6) {
struct sockaddr_in6 * addr_in6 = (struct sockaddr_in6 *)&addr_storage;
str.append(":").append(std::to_string(ntohs(addr_in->sin_port)));
} else if (addr_storage.ss_family == AF_INET6) {
struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6*) &addr_storage;
str.append(conv::toString(addr_in6->sin6_addr));
str.append(":").append(std::to_string(ntohs(addr_in6->sin6_port)));
str.append(":").append(std::to_string(ntohs(addr_in6->sin6_port)));
}
return str;
}
......
......@@ -35,7 +35,8 @@
Logger *Logger::m_singleton = NULL;
void Logger::_init(const char *app, const bool log_stdout, const bool log_rot_file){
//------------------------------------------------------------------------------
void Logger::_init(const char *app, const bool log_stdout, const bool log_rot_file) {
int num_sinks = 0;
spdlog::set_async_mode(2048);
#if TRACE_IS_ON
......@@ -48,14 +49,14 @@ void Logger::_init(const char *app, const bool log_stdout, const bool log_rot_fi
spdlog::level::level_enum llevel = spdlog::level::warn;
#endif
if(log_stdout){
std::string filename = fmt::format("./{}.log",app);
if (log_stdout) {
std::string filename = fmt::format("./{}.log", app);
m_sinks.push_back(std::make_shared<spdlog::sinks::ansicolor_stdout_sink_mt>());
m_sinks[num_sinks++].get()->set_level(llevel);
}
if(log_rot_file){
std::string filename = fmt::format("./{}.log",app);
m_sinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>(filename, 5*1024*1024, 3));
if (log_rot_file) {
std::string filename = fmt::format("./{}.log", app);
m_sinks.push_back(std::make_shared < spdlog::sinks::rotating_file_sink_mt > (filename, 5 * 1024 * 1024, 3));
}
std::stringstream ss;
......@@ -79,10 +80,11 @@ void Logger::_init(const char *app, const bool log_stdout, const bool log_rot_fi
}
_Logger::_Logger( const char *category, std::vector<spdlog::sink_ptr> &sinks, const char *pattern )
: m_log( category, sinks.begin(), sinks.end() )
{
m_log.set_pattern( pattern );
//------------------------------------------------------------------------------
_Logger::_Logger(const char *category, std::vector<spdlog::sink_ptr> &sinks, const char *pattern)
:
m_log(category, sinks.begin(), sinks.end()) {
m_log.set_pattern(pattern);
#if TRACE_IS_ON
m_log.set_level( spdlog::level::trace );
#elif DEBUG_IS_ON
......@@ -90,12 +92,12 @@ _Logger::_Logger( const char *category, std::vector<spdlog::sink_ptr> &sinks, co
#elif INFO_IS_ON
m_log.set_level( spdlog::level::info );
#else
m_log.set_level( spdlog::level::warn );
m_log.set_level(spdlog::level::warn);
#endif
}
void _Logger::trace( const char *format, ... )
{
//------------------------------------------------------------------------------
void _Logger::trace(const char *format, ...) {
#if TRACE_IS_ON
va_list args;
va_start( args, format );
......@@ -104,8 +106,8 @@ void _Logger::trace( const char *format, ... )
#endif
}
void _Logger::trace( const std::string &format, ... )
{
//------------------------------------------------------------------------------
void _Logger::trace(const std::string &format, ...) {
#if TRACE_IS_ON
va_list args;
va_start( args, format );
......@@ -114,8 +116,8 @@ void _Logger::trace( const std::string &format, ... )
#endif
}
void _Logger::debug( const char *format, ... )
{
//------------------------------------------------------------------------------
void _Logger::debug(const char *format, ...) {
#if DEBUG_IS_ON
va_list args;
va_start( args, format );
......@@ -124,8 +126,8 @@ void _Logger::debug( const char *format, ... )
#endif
}
void _Logger::debug( const std::string &format, ... )
{
//------------------------------------------------------------------------------
void _Logger::debug(const std::string &format, ...) {
#if DEBUG_IS_ON
va_list args;
va_start( args, format );
......@@ -134,8 +136,8 @@ void _Logger::debug( const std::string &format, ... )
#endif
}
void _Logger::info( const char *format, ... )
{
//------------------------------------------------------------------------------
void _Logger::info(const char *format, ...) {
#if INFO_IS_ON
va_list args;
va_start( args, format );
......@@ -144,8 +146,8 @@ void _Logger::info( const char *format, ... )
#endif
}
void _Logger::info( const std::string &format, ... )
{
//------------------------------------------------------------------------------
void _Logger::info(const std::string &format, ...) {
#if INFO_IS_ON
va_list args;
va_start( args, format );
......@@ -154,89 +156,79 @@ void _Logger::info( const std::string &format, ... )
#endif
}
void _Logger::startup( const char *format, ... )
{
//------------------------------------------------------------------------------
void _Logger::startup(const char *format, ...) {
va_list args;
va_start( args, format );
log( _ltStartup, format, args );
va_end( args );
va_start(args, format);
log(_ltStartup, format, args);
va_end(args);
}
void _Logger::startup( const std::string &format, ... )
{
//------------------------------------------------------------------------------
void _Logger::startup(const std::string &format, ...) {
va_list args;
va_start( args, format );
log( _ltStartup, format.c_str(), args );
va_end( args );
va_start(args, format);
log(_ltStartup, format.c_str(), args);
va_end(args);
}
void _Logger::warn( const char *format, ... )
{
//------------------------------------------------------------------------------
void _Logger::warn(const char *format, ...) {
va_list args;
va_start( args, format );
log( _ltWarn, format, args );
va_end( args );
va_start(args, format);
log(_ltWarn, format, args);
va_end(args);
}
void _Logger::warn( const std::string &format, ... )
{
//------------------------------------------------------------------------------
void _Logger::warn(const std::string &format, ...) {
va_list args;
va_start( args, format );
log( _ltWarn, format.c_str(), args );
va_end( args );
va_start(args, format);
log(_ltWarn, format.c_str(), args);
va_end(args);
}
void _Logger::error( const char *format, ... )
{
//------------------------------------------------------------------------------
void _Logger::error(const char *format, ...) {
va_list args;
va_start( args, format );
log( _ltError, format, args );
va_end( args );
va_start(args, format);
log(_ltError, format, args);
va_end(args);
}
void _Logger::error( const std::string &format, ... )
{
//------------------------------------------------------------------------------
void _Logger::error(const std::string &format, ...) {
va_list args;
va_start( args, format );
log( _ltError, format.c_str(), args );
va_end( args );
va_start(args, format);
log(_ltError, format.c_str(), args);
va_end(args);
}
void _Logger::log( _LogType lt, const char *format, va_list &args )
{
char buffer[ 2048 ];
vsnprintf( buffer, sizeof(buffer), format, args );
switch ( lt )
{
case _ltTrace: m_log.trace( buffer ); break;
case _ltDebug: m_log.debug( buffer ); break;
case _ltInfo: m_log.info( buffer ); break;
case _ltStartup: m_log.warn( buffer ); break;
case _ltWarn: m_log.error( buffer ); break;
case _ltError: m_log.critical( buffer ); break;
//------------------------------------------------------------------------------
void _Logger::log(_LogType lt, const char *format, va_list &args) {
char buffer[2048];
vsnprintf(buffer, sizeof(buffer), format, args);
switch (lt) {
case _ltTrace:
m_log.trace(buffer);
break;
case _ltDebug:
m_log.debug(buffer);
break;
case _ltInfo:
m_log.info(buffer);
break;
case _ltStartup:
m_log.warn(buffer);
break;
case _ltWarn:
m_log.error(buffer);
break;
case _ltError:
m_log.critical(buffer);
break;
}
}
......@@ -37,17 +37,21 @@
#define SPDLOG_ENABLE_SYSLOG
#include "spdlog/spdlog.h"
class LoggerException : public std::runtime_error
{
public:
explicit LoggerException(const char *m) : std::runtime_error(m) {}
explicit LoggerException(const std::string &m) : std::runtime_error(m) {}
class LoggerException : public std::runtime_error {
public:
explicit LoggerException(const char *m)
:
std::runtime_error(m) {
}
explicit LoggerException(const std::string &m)
:
std::runtime_error(m) {
}
};
class _Logger
{
public:
_Logger(const char * category, std::vector<spdlog::sink_ptr> &sinks, const char *pattern);
class _Logger {
public:
_Logger(const char *category, std::vector<spdlog::sink_ptr> &sinks, const char *pattern);
void trace(const char *format, ...);
void trace(const std::string &format, ...);
......@@ -62,10 +66,9 @@ public:
void error(const char *format, ...);
void error(const std::string &format, ...);
private:
private:
_Logger();
enum _LogType
{
enum _LogType {
_ltTrace,
_ltDebug,
_ltInfo,
......@@ -78,35 +81,74 @@ private:
spdlog::logger m_log;
};
class Logger
{
public:
static void init(const char *app, const bool log_stdout, const bool log_rot_file){singleton()._init(app, log_stdout, log_rot_file);}
static void init(const std::string &app, const bool log_stdout, const bool log_rot_file){init(app.c_str(), log_stdout, log_rot_file);}
static _Logger &async_cmd(){return *singleton().m_async_cmd;}
static _Logger &amf_app(){return *singleton().m_amf_app;}
static _Logger &config(){return *singleton().m_config;}
static _Logger &system(){return *singleton().m_system;}
static _Logger &sctp(){return *singleton().m_sctp;}
static _Logger &nas_mm(){return *singleton().m_nas_mm;}
static _Logger &ngap(){return *singleton().m_ngap;}
static _Logger &itti(){return *singleton().m_itti;}
static _Logger &amf_n2(){return *singleton().m_amf_n2;}
static _Logger &task_amf_n2(){return *singleton().m_task_amf_n2;}
static _Logger &amf_n1(){return *singleton().m_amf_n1;}
static _Logger &task_amf_n1(){return *singleton().m_task_amf_n1;}
static _Logger &amf_n11(){return *singleton().m_amf_n11;}
static _Logger &task_amf_n11(){return *singleton().m_task_amf_n11;}
static _Logger &amf_server(){return *singleton().m_amf_server;}
private:
class Logger {
public:
static void init(const char *app, const bool log_stdout, const bool log_rot_file) {
singleton()._init(app, log_stdout, log_rot_file);
}
static void init(const std::string &app, const bool log_stdout, const bool log_rot_file) {
init(app.c_str(), log_stdout, log_rot_file);
}
static _Logger& async_cmd() {
return *singleton().m_async_cmd;
}
static _Logger& amf_app() {
return *singleton().m_amf_app;
}
static _Logger& config() {
return *singleton().m_config;
}
static _Logger& system() {
return *singleton().m_system;
}
static _Logger& sctp() {
return *singleton().m_sctp;
}
static _Logger& nas_mm() {
return *singleton().m_nas_mm;
}
static _Logger& ngap() {
return *singleton().m_ngap;
}
static _Logger& itti() {
return *singleton().m_itti;
}
static _Logger& amf_n2() {
return *singleton().m_amf_n2;
}
static _Logger& task_amf_n2() {
return *singleton().m_task_amf_n2;
}
static _Logger& amf_n1() {
return *singleton().m_amf_n1;
}
static _Logger& task_amf_n1() {
return *singleton().m_task_amf_n1;
}
static _Logger& amf_n11() {
return *singleton().m_amf_n11;
}
static _Logger& task_amf_n11() {
return *singleton().m_task_amf_n11;
}
static _Logger& amf_server() {
return *singleton().m_amf_server;
}
private:
static Logger *m_singleton;
static Logger &singleton(){if(!m_singleton) m_singleton = new Logger(); return *m_singleton;}
static Logger& singleton() {
if (!m_singleton)
m_singleton = new Logger();
return *m_singleton;
}
Logger(){}
~Logger(){}
Logger() {
}
~Logger() {
}
void _init(const char *app, const bool log_stdout, const bool log_rot_file);
......@@ -134,8 +176,3 @@ private:
#endif
......@@ -28,4 +28,3 @@
#include "gNB_context.hpp"
......@@ -34,36 +34,36 @@
#include <vector>
#include "sctp_server.hpp"
#include "NgapIEsStruct.hpp"
extern "C"{
#include "Ngap_PagingDRX.h"
#include "bstrlib.h"
extern "C" {
#include "Ngap_PagingDRX.h"
#include "bstrlib.h"
}
using namespace sctp;
using namespace std;
using namespace ngap;
enum amf_ng_gnb_state_s{
NGAP_INIT,
NGAP_RESETING,
NGAP_READY,
NGAP_SHUTDOWN
enum amf_ng_gnb_state_s {
NGAP_INIT,
NGAP_RESETING,
NGAP_READY,
NGAP_SHUTDOWN
};
class gnb_context{
public:
class gnb_context {
public:
enum amf_ng_gnb_state_s ng_state;
string gnb_name;
long globalRanNodeId;
e_Ngap_PagingDRX default_paging_drx; //v32, v64, v128, v256
vector<SupportedItem_t> s_ta_list;
bstring ue_radio_cap_ind;
sctp_assoc_id_t sctp_assoc_id;
sctp_stream_id_t next_sctp_stream;
sctp_stream_id_t instreams;
sctp_stream_id_t outstreams;
string gnb_name;
long globalRanNodeId;
e_Ngap_PagingDRX default_paging_drx; //v32, v64, v128, v256
vector<SupportedItem_t> s_ta_list;
bstring ue_radio_cap_ind;
sctp_assoc_id_t sctp_assoc_id;
sctp_stream_id_t next_sctp_stream;
sctp_stream_id_t instreams;
sctp_stream_id_t outstreams;
};
#endif
......@@ -28,7 +28,8 @@
#include "nas_context.hpp"
nas_context::nas_context(){
//------------------------------------------------------------------------------
nas_context::nas_context() {
security_ctx = NULL;
is_imsi_present = false;
is_stacs_available = false;
......@@ -43,4 +44,6 @@ nas_context::nas_context(){
auts = NULL;
}
nas_context::~nas_context(){}
//------------------------------------------------------------------------------
nas_context::~nas_context() {
}
......@@ -36,69 +36,56 @@
#include "nas_security_context.hpp"
#include "struct.hpp"
class nas_context{
public:
class nas_context {
public:
nas_context();
~nas_context();
public:
bool ctx_avaliability_ind;
bool is_stacs_available;
long amf_ue_ngap_id;
uint32_t ran_ue_ngap_id;
string nas_status;
/************ parameters from Registration request *************/
uint8_t registration_type:3;
bool follow_on_req_pending_ind;
uint8_t ngKsi:4;
public:
bool ctx_avaliability_ind;
bool is_stacs_available;
long amf_ue_ngap_id;
uint32_t ran_ue_ngap_id;
string nas_status;
/************ parameters from Registration request *************/
uint8_t registration_type :3;
bool follow_on_req_pending_ind;
uint8_t ngKsi :4;
//mobility identity: imsi, supi, 5g-guti, etc
std::string imsi;
uint8_t mmCapability;
uint8_t ueSecurityCapEnc;
uint8_t ueSecurityCapInt;
std::vector<nas::SNSSAI_t> requestedNssai;
std::string serving_network;
bstring auts;
/************ NAS EP(s) ****************/
bool is_specific_procedure_for_registration_running;
bool is_specific_procedure_for_deregistration_running;
bool is_specific_procedure_for_eCell_inactivity_running;
bool is_common_procedure_for_authentication_running;
bool is_common_procedure_for_identification_running;
bool is_common_procedure_for_security_mode_control_running;
bool is_common_procedure_for_nas_transport_running;
/************ security related ***********/
std::string imsi;
uint8_t mmCapability;
uint8_t ueSecurityCapEnc;
uint8_t ueSecurityCapInt;
std::vector<nas::SNSSAI_t> requestedNssai;
std::string serving_network;
bstring auts;
/************ NAS EP(s) ****************/
bool is_specific_procedure_for_registration_running;
bool is_specific_procedure_for_deregistration_running;
bool is_specific_procedure_for_eCell_inactivity_running;
bool is_common_procedure_for_authentication_running;
bool is_common_procedure_for_identification_running;
bool is_common_procedure_for_security_mode_control_running;
bool is_common_procedure_for_nas_transport_running;
/************ security related ***********/
#define MAX_5GS_AUTH_VECTORS 1
auc_vector_t _vector[MAX_5GS_AUTH_VECTORS];/* 5GS authentication vector */
_5G_HE_AV_t _5g_he_av[MAX_5GS_AUTH_VECTORS];//generated by UDM
_5G_AV_t _5g_av[MAX_5GS_AUTH_VECTORS];//generated by ausf
uint8_t kamf[MAX_5GS_AUTH_VECTORS][32];
auc_vector_t _vector[MAX_5GS_AUTH_VECTORS];/* 5GS authentication vector */
_5G_HE_AV_t _5g_he_av[MAX_5GS_AUTH_VECTORS]; //generated by UDM
_5G_AV_t _5g_av[MAX_5GS_AUTH_VECTORS]; //generated by ausf
uint8_t kamf[MAX_5GS_AUTH_VECTORS][32];
security_context_t _security;
nas_secu_ctx *security_ctx;
nas_secu_ctx *security_ctx;
bool is_current_security_avaliable;
bool is_current_security_available;
int registration_attempt_counter;//used to limit the subsequently reject registration attempts(clause 5.5.1.2.7/5.5.1.3.7, 3gpp ts24.501)
/**************** parameters present? ****************/
bool is_imsi_present;
bool is_5g_guti_present;
bool is_auth_vectors_present;
int registration_attempt_counter; //used to limit the subsequently reject registration attempts(clause 5.5.1.2.7/5.5.1.3.7, 3gpp ts24.501)
/**************** parameters present? ****************/
bool is_imsi_present;
bool is_5g_guti_present;
bool is_auth_vectors_present;
};
#endif
......@@ -41,72 +41,71 @@ typedef enum {
SECURITY_CTX_TYPE_NOT_AVAILABLE = 0,
SECURITY_CTX_TYPE_PARTIAL_NATIVE,
SECURITY_CTX_TYPE_FULL_NATIVE,
SECURITY_CTX_TYPE_MAPPED
SECURITY_CTX_TYPE_MAPPED
} nas_sc_type_t;
/*
Internal data used for security mode control procedure
*/
Internal data used for security mode control procedure
*/
typedef struct {
unsigned int ue_id; /* UE identifier */
unsigned int ue_id; /* UE identifier */
#define SECURITY_COUNTER_MAX 5
unsigned int retransmission_count; /* Retransmission counter */
int ksi; /* NAS key set identifier */
int nea; /* Replayed EPS encryption algorithms */
int eea; /* Replayed EPS encryption algorithms */
int nia; /* Replayed EPS integrity algorithms */
int eia; /* Replayed EPS integrity algorithms */
int ucs2; /* Replayed Alphabet */
int uea; /* Replayed UMTS encryption algorithms */
int uia; /* Replayed UMTS integrity algorithms */
int gea; /* Replayed G encryption algorithms */
bool umts_present;
bool gprs_present;
int selected_eea; /* Selected EPS encryption algorithms */
int selected_eia; /* Selected EPS integrity algorithms */
int saved_selected_eea; /* Previous selected EPS encryption algorithms */
int saved_selected_nea; /* Previous selected EPS encryption algorithms */
int saved_selected_eia; /* Previous selected EPS integrity algorithms */
int saved_selected_nia; /* Previous selected EPS integrity algorithms */
int saved_ngksi; /* Previous ksi */
uint16_t saved_overflow; /* Previous dl_count overflow */
uint8_t saved_seq_num; /* Previous dl_count seq_num */
nas_sc_type_t saved_sc_type;
bool notify_failure; /* Indicates whether the identification
* procedure failure shall be notified
* to the ongoing EMM procedure */
unsigned int retransmission_count; /* Retransmission counter */
int ksi; /* NAS key set identifier */
int nea; /* Replayed EPS encryption algorithms */
int eea; /* Replayed EPS encryption algorithms */
int nia; /* Replayed EPS integrity algorithms */
int eia; /* Replayed EPS integrity algorithms */
int ucs2; /* Replayed Alphabet */
int uea; /* Replayed UMTS encryption algorithms */
int uia; /* Replayed UMTS integrity algorithms */
int gea; /* Replayed G encryption algorithms */
bool umts_present;
bool gprs_present;
int selected_eea; /* Selected EPS encryption algorithms */
int selected_eia; /* Selected EPS integrity algorithms */
int saved_selected_eea; /* Previous selected EPS encryption algorithms */
int saved_selected_nea; /* Previous selected EPS encryption algorithms */
int saved_selected_eia; /* Previous selected EPS integrity algorithms */
int saved_selected_nia; /* Previous selected EPS integrity algorithms */
int saved_ngksi; /* Previous ksi */
uint16_t saved_overflow; /* Previous dl_count overflow */
uint8_t saved_seq_num; /* Previous dl_count seq_num */
nas_sc_type_t saved_sc_type;
bool notify_failure; /* Indicates whether the identification
* procedure failure shall be notified
* to the ongoing EMM procedure */
} security_data_t;
typedef uint8_t ngksi_t;
typedef struct{
uint32_t spare:8;
uint32_t overflow:16;
uint32_t seq_num:8;
}count_t;
typedef struct {
uint32_t spare :8;
uint32_t overflow :16;
uint32_t seq_num :8;
} count_t;
typedef struct{
typedef struct {
uint8_t _5gs_encryption;
uint8_t _5gs_integrity;
}capability_t;
} capability_t;
typedef struct{
uint8_t encryption:4;
uint8_t integrity:4;
}selected_algs;
typedef struct {
uint8_t encryption :4;
uint8_t integrity :4;
} selected_algs;
class nas_secu_ctx{
public:
int vector_pointer;
class nas_secu_ctx {
public:
int vector_pointer;
nas_sc_type_t sc_type;
ngksi_t ngksi;
uint8_t knas_enc[AUTH_KNAS_ENC_SIZE];
uint8_t knas_int[AUTH_KNAS_INT_SIZE];
count_t dl_count;
count_t ul_count;
capability_t ue_algorithms;
selected_algs nas_algs;
ngksi_t ngksi;
uint8_t knas_enc[AUTH_KNAS_ENC_SIZE];
uint8_t knas_int[AUTH_KNAS_INT_SIZE];
count_t dl_count;
count_t ul_count;
capability_t ue_algorithms;
selected_algs nas_algs;
};
#endif
......@@ -28,8 +28,11 @@
#include "pdu_session_context.hpp"
pdu_session_context::pdu_session_context(){
//------------------------------------------------------------------------------
pdu_session_context::pdu_session_context() {
smf_avaliable = false;
}
pdu_session_context::~pdu_session_context(){}
//------------------------------------------------------------------------------
pdu_session_context::~pdu_session_context() {
}
......@@ -33,18 +33,18 @@
#include "bstrlib.h"
using namespace std;
class pdu_session_context{
public:
class pdu_session_context {
public:
pdu_session_context();
~pdu_session_context();
public:
public:
uint32_t ran_ue_ngap_id;
long amf_ue_ngap_id;
long amf_ue_ngap_id;
uint8_t req_type;
uint8_t pdu_session_id;
bstring n2sm;
string dnn;
string remote_smf_addr[0];//"192.168.12.10:8080"
string remote_smf_addr[0]; //"192.168.12.10:8080"
bool smf_avaliable;
};
#endif
......@@ -29,7 +29,6 @@
#ifndef _SECURITY_DEF_H_
#define _SECURITY_DEF_H_
#define AUTH_SQN_INDEX 0
#define AUTH_AMF_INDEX (AUTH_SQN_INDEX + AUTH_SQN_SIZE)
#define AUTH_MAC_INDEX (AUTH_AMF_INDEX + AUTH_AMF_SIZE)
......@@ -76,35 +75,37 @@ typedef struct {
typedef struct security_context_s {
//emm_sc_type_t sc_type; /* Type of security context */
/* state of security context is implicit due to its storage location (current/non-current)*/
/* state of security context is implicit due to its storage location (current/non-current)*/
#define EKSI_MAX_VALUE 6
//ksi_t eksi; /* NAS key set identifier for E-UTRAN */
#define EMM_SECURITY_VECTOR_INDEX_INVALID (-1)
int vector_index; /* Pointer on vector */
int vector_index; /* Pointer on vector */
uint8_t knas_enc[AUTH_KNAS_ENC_SIZE];/* NAS cyphering key */
uint8_t knas_int[AUTH_KNAS_INT_SIZE];/* NAS integrity key */
struct count_s{
uint32_t spare:8;
uint32_t overflow:16;
uint32_t seq_num:8;
} dl_count, ul_count; /* Downlink and uplink count parameters */
struct count_s {
uint32_t spare :8;
uint32_t overflow :16;
uint32_t seq_num :8;
} dl_count, ul_count; /* Downlink and uplink count parameters */
struct {
uint8_t eps_encryption; /* algorithm used for ciphering */
uint8_t eps_integrity; /* algorithm used for integrity protection */
uint8_t umts_encryption; /* algorithm used for ciphering */
uint8_t umts_integrity; /* algorithm used for integrity protection */
uint8_t gprs_encryption; /* algorithm used for ciphering */
bool umts_present:1;
bool gprs_present:1;
} capability; /* UE network capability */
uint8_t eps_encryption; /* algorithm used for ciphering */
uint8_t eps_integrity; /* algorithm used for integrity protection */
uint8_t umts_encryption; /* algorithm used for ciphering */
uint8_t umts_integrity; /* algorithm used for integrity protection */
uint8_t gprs_encryption; /* algorithm used for ciphering */
bool umts_present :1;
bool gprs_present :1;
} capability; /* UE network capability */
struct {
uint8_t encryption:4; /* algorithm used for ciphering */
uint8_t integrity:4; /* algorithm used for integrity protection */
} selected_algorithms; /* MME selected algorithms */
uint8_t encryption :4; /* algorithm used for ciphering */
uint8_t integrity :4; /* algorithm used for integrity protection */
} selected_algorithms; /* MME selected algorithms */
// Requirement MME24.301R10_4.4.4.3_2 (DETACH REQUEST (if sent before security has been activated);)
uint8_t activated;
uint8_t activated;
} security_context_t;
#endif
......@@ -34,21 +34,21 @@
#include "NgapIEsStruct.hpp"
#include <shared_mutex>
extern "C"{
#include "Ngap_RRCEstablishmentCause.h"
extern "C" {
#include "Ngap_RRCEstablishmentCause.h"
}
using namespace ngap;
class ue_context{
public:
uint32_t ran_ue_ngap_id;//32bits
long amf_ue_ngap_id:40;//40bits
class ue_context {
public:
uint32_t ran_ue_ngap_id; //32bits
long amf_ue_ngap_id :40; //40bits
e_Ngap_RRCEstablishmentCause rrc_estb_cause;
bool isUeContextRequest;
NrCgi_t cgi;
Tai_t tai;
Tai_t tai;
};
#endif
......@@ -35,29 +35,29 @@
#include <shared_mutex>
using namespace sctp;
typedef enum{
typedef enum {
NGAP_UE_INVALID_STATE,
NGAP_UE_WAITING_CSR,//Context Setup Response(CSR)
NGAP_UE_WAITING_CSR, //Context Setup Response(CSR)
NGAP_UE_HANDOVER,
NGAP_UE_CONNECTED,
NGAP_UE_WAITING_CRR
}ng_ue_state_t;
} ng_ue_state_t;
class ue_ngap_context{
public:
uint32_t ran_ue_ngap_id;//32bits
long amf_ue_ngap_id:40;//40bits
class ue_ngap_context {
public:
uint32_t ran_ue_ngap_id; //32bits
long amf_ue_ngap_id :40; //40bits
sctp_stream_id_t sctp_stream_recv;// used to decide which ue in gNB
sctp_stream_id_t sctp_stream_send;// used to decide which ue in gNB
sctp_assoc_id_t gnb_assoc_id;//to find which gnb this UE belongs to
sctp_stream_id_t sctp_stream_recv; // used to decide which ue in gNB
sctp_stream_id_t sctp_stream_send; // used to decide which ue in gNB
bool ueContextRequest;
uint32_t s_tmsi_5g;
sctp_assoc_id_t gnb_assoc_id; //to find which gnb this UE belongs to
bool ueContextRequest;
uint32_t s_tmsi_5g;
//state management, ue status over the air
ng_ue_state_t ng_ue_state;
ng_ue_state_t ng_ue_state;
};
#endif
This diff is collapsed.
......@@ -11,25 +11,26 @@
#include "ngap_app.hpp"
#include "itti.hpp"
using namespace std;
using namespace config;
using namespace ngap;
amf_config amf_cfg;
ngap_app * ngap_inst = NULL;
ngap_app *ngap_inst = NULL;
itti_mw *itti_inst = nullptr;
void amf_ngap_app_task(void*){
//------------------------------------------------------------------------------
void amf_ngap_app_task(void*) {
const task_id_t task_id = TASK_NGAP_APP;
itti_inst->notify_task_ready(task_id);
Logger::itti().debug("task(%d) ready",TASK_NGAP_APP);
Logger::itti().debug("task(%d) ready", TASK_NGAP_APP);
}
int main(int argc, char **argv){
//------------------------------------------------------------------------------
int main(int argc, char **argv) {
srand (time(NULL));
if(!Options::parse(argc, argv)){
if (!Options::parse(argc, argv)) {
cout<<"Options::parse() failed"<<endl;
return 1;
}
......@@ -45,7 +46,7 @@ int main(int argc, char **argv){
itti_inst = new itti_mw();
//itti_inst->start(amf_cfg.itti.itti_timer_sched_params);
itti_inst->create_task(TASK_NGAP_APP, amf_ngap_app_task,nullptr);
itti_inst->create_task(TASK_NGAP_APP, amf_ngap_app_task,nullptr);
Logger::amf_app().debug("Initiating Done!");
pause();
......
......@@ -27,7 +27,7 @@
#include <cstring>
#include "normalizer.hh"
extern void hexStr2Byte(const char* src, unsigned char *dest, int len);
extern void hexStr2Byte(const char *src, unsigned char *dest, int len);
extern void print_buffer(const std::string app, const std::string commit, uint8_t *buf, int len);
extern void ue_gnb_simulator();
......@@ -43,11 +43,11 @@ itti_mw *itti_inst = nullptr;
amf_app *amf_app_inst = nullptr;
statistics stacs;
int main(int argc, char **argv){
//------------------------------------------------------------------------------
int main(int argc, char **argv) {
srand (time(NULL));
if(!Options::parse(argc, argv)){
if (!Options::parse(argc, argv)) {
cout<<"Options::parse() failed"<<endl;
return 1;
}
......@@ -59,7 +59,7 @@ int main(int argc, char **argv){
amf_cfg.display();
modules.load(Options::getlibconfigConfig());
modules.display();
itti_inst = new itti_mw();
itti_inst->start(amf_cfg.itti.itti_timer_sched_params);
//itti_inst->start();
......@@ -68,7 +68,7 @@ int main(int argc, char **argv){
amf_app_inst->allRegistredModulesInit(modules);
Logger::amf_app().debug("initiating amf server endpoints");
Pistache::Address addr(std::string(inet_ntoa (*((struct in_addr *)&amf_cfg.n2.addr4))) , Pistache::Port(8282));
Pistache::Address addr(std::string(inet_ntoa (*((struct in_addr *)&amf_cfg.n2.addr4))) , Pistache::Port(8282));
AMFApiServer amfApiServer(addr, amf_app_inst);
amfApiServer.init(2);
std::thread amf_api_manager(&AMFApiServer::start, amfApiServer);
......
/*
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#include <iostream>
#include <stdlib.h>
......@@ -28,84 +27,93 @@ std::string Options::m_libconfigcfg;
bool Options::m_log_rot_file_log;
bool Options::m_log_stdout;
void Options::help()
{
std::cout << std::endl
<< "Usage: smf [OPTIONS]..." << std::endl
<< " -h, --help Print help and exit" << std::endl
<< " -c, --libconfigcfg filename Read the application configuration from this file." << std::endl
<< " -o, --stdoutlog Send the application logs to STDOUT fd." << std::endl
<< " -r, --rotatelog Send the application logs to local file (in current working directory)." << std::endl
;
//------------------------------------------------------------------------------
void Options::help() {
std::cout << std::endl << "Usage: smf [OPTIONS]..." << std::endl << " -h, --help Print help and exit" << std::endl << " -c, --libconfigcfg filename Read the application configuration from this file." << std::endl
<< " -o, --stdoutlog Send the application logs to STDOUT fd." << std::endl << " -r, --rotatelog Send the application logs to local file (in current working directory)." << std::endl;
}
bool Options::parse( int argc, char **argv ){
//------------------------------------------------------------------------------
bool Options::parse(int argc, char **argv) {
bool ret = true;
bool ret = true;
ret = parseInputOptions( argc, argv );
ret &= validateOptions();
return ret;
ret = parseInputOptions(argc, argv);
ret &= validateOptions();
return ret;
}
//------------------------------------------------------------------------------
bool Options::validateOptions() {
bool Options::validateOptions(){
return (
(options & libconfigcfg)
);
return ((options & libconfigcfg));
}
bool Options::parseInputOptions( int argc, char **argv )
{
int c;
int option_index = 0;
bool result = true;
struct option long_options[] = {
{ "help", no_argument, NULL, 'h' },
{ "libconfigcfg", required_argument, NULL, 'f' },
{ "stdoutlog", no_argument, NULL, 'o' },
{ "rotatelog", no_argument, NULL, 'r' },
{ NULL,0,NULL,0 }
};
// Loop on arguments
while (1)
{
c = getopt_long(argc, argv, "horc:", long_options, &option_index );
if (c == -1)
break; // Exit from the loop.
switch (c)
{
case 'h': { help(); exit(0); break; }
case 'c': { m_libconfigcfg = optarg; options |= libconfigcfg; break; }
case 'o': { m_log_stdout = true; options |= log_stdout; break; }
case 'r': { m_log_rot_file_log = true; options |= log_rot_file_log; break; }
case '?':
{
switch ( optopt )
{
case 'c': { std::cout << "Option -l (libconfig config) requires an argument" << std::endl; break; }
case 'o': { std::cout << "Option -o do not requires an argument, can be also set with option -r." << std::endl; break; }
case 'r': { std::cout << "Option -r do not requires an argument, can be also set with option -o." << std::endl; break; }
default: { std::cout << "Unrecognized option [" << c << "]" << std::endl; break; }
}
result = false;
//------------------------------------------------------------------------------
bool Options::parseInputOptions(int argc, char **argv) {
int c;
int option_index = 0;
bool result = true;
struct option long_options[] = { { "help", no_argument, NULL, 'h' }, { "libconfigcfg", required_argument, NULL, 'f' }, { "stdoutlog", no_argument, NULL, 'o' }, { "rotatelog", no_argument, NULL, 'r' }, { NULL, 0, NULL, 0 } };
// Loop on arguments
while (1) {
c = getopt_long(argc, argv, "horc:", long_options, &option_index);
if (c == -1)
break; // Exit from the loop.
switch (c) {
case 'h': {
help();
exit(0);
break;
}
case 'c': {
m_libconfigcfg = optarg;
options |= libconfigcfg;
break;
}
case 'o': {
m_log_stdout = true;
options |= log_stdout;
break;
}
case 'r': {
m_log_rot_file_log = true;
options |= log_rot_file_log;
break;
}
case '?': {
switch (optopt) {
case 'c': {
std::cout << "Option -l (libconfig config) requires an argument" << std::endl;
break;
}
case 'o': {
std::cout << "Option -o do not requires an argument, can be also set with option -r." << std::endl;
break;
}
default:
{
}
case 'r': {
std::cout << "Option -r do not requires an argument, can be also set with option -o." << std::endl;
break;
}
default: {
std::cout << "Unrecognized option [" << c << "]" << std::endl;
result = false;
}
break;
}
}
result = false;
break;
}
default: {
std::cout << "Unrecognized option [" << c << "]" << std::endl;
result = false;
}
}
return result;
}
}
return result;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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