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

apply simple format

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