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

apply simple format

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