diff --git a/srsepc/hdr/hss/hss.h b/srsepc/hdr/hss/hss.h index b64f93916..4089396a9 100644 --- a/srsepc/hdr/hss/hss.h +++ b/srsepc/hdr/hss/hss.h @@ -28,17 +28,17 @@ #ifndef SRSEPC_HSS_H #define SRSEPC_HSS_H -#include +#include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" -#include "srslte/common/logger_file.h" #include "srslte/common/log_filter.h" -#include "srslte/common/buffer_pool.h" +#include "srslte/common/logger_file.h" #include "srslte/interfaces/epc_interfaces.h" +#include #include #include -#define LTE_FDD_ENB_IND_HE_N_BITS 5 -#define LTE_FDD_ENB_IND_HE_MASK 0x1FUL +#define LTE_FDD_ENB_IND_HE_N_BITS 5 +#define LTE_FDD_ENB_IND_HE_MASK 0x1FUL #define LTE_FDD_ENB_IND_HE_MAX_VALUE 31 #define LTE_FDD_ENB_SEQ_HE_MAX_VALUE 0x07FFFFFFFFFFUL @@ -116,7 +116,7 @@ private: std::string hex_string(uint8_t* hex, int size); - std::string db_file; + std::string db_file; /*Logs*/ srslte::log_filter* m_hss_log; diff --git a/srsepc/hdr/mbms-gw/mbms-gw.h b/srsepc/hdr/mbms-gw/mbms-gw.h index 76e38e1dd..6339e0e95 100644 --- a/srsepc/hdr/mbms-gw/mbms-gw.h +++ b/srsepc/hdr/mbms-gw/mbms-gw.h @@ -37,8 +37,7 @@ #include "srslte/srslte.h" #include -namespace srsepc{ - +namespace srsepc { const uint16_t GTPU_RX_PORT = 2152; @@ -52,47 +51,44 @@ typedef struct { int m1u_multi_ttl; } mbms_gw_args_t; -struct pseudo_hdr -{ - uint32_t src_addr; - uint32_t dst_addr; - uint8_t placeholder; - uint8_t protocol; - uint16_t udp_len; +struct pseudo_hdr { + uint32_t src_addr; + uint32_t dst_addr; + uint8_t placeholder; + uint8_t protocol; + uint16_t udp_len; }; -class mbms_gw: - public thread +class mbms_gw : public thread { public: static mbms_gw* get_instance(void); - static void cleanup(void); - int init(mbms_gw_args_t* args, srslte::log_filter *mbms_gw_log); - void stop(); - void run_thread(); + static void cleanup(void); + int init(mbms_gw_args_t* args, srslte::log_filter* mbms_gw_log); + void stop(); + void run_thread(); private: - /* Methods */ mbms_gw(); virtual ~mbms_gw(); - static mbms_gw *m_instance; + static mbms_gw* m_instance; - int init_sgi_mb_if(mbms_gw_args_t *args); - int init_m1_u(mbms_gw_args_t *args); - void handle_sgi_md_pdu(srslte::byte_buffer_t *msg); - uint16_t in_cksum(uint16_t *iphdr, int count); + int init_sgi_mb_if(mbms_gw_args_t* args); + int init_m1_u(mbms_gw_args_t* args); + void handle_sgi_md_pdu(srslte::byte_buffer_t* msg); + uint16_t in_cksum(uint16_t* iphdr, int count); /* Members */ - bool m_running; - srslte::byte_buffer_pool *m_pool; - srslte::log_filter *m_mbms_gw_log; + bool m_running; + srslte::byte_buffer_pool* m_pool; + srslte::log_filter* m_mbms_gw_log; bool m_sgi_mb_up; - int m_sgi_mb_if; + int m_sgi_mb_if; - bool m_m1u_up; - int m_m1u; + bool m_m1u_up; + int m_m1u; struct sockaddr_in m_m1u_multi_addr; }; diff --git a/srsepc/hdr/mme/mme.h b/srsepc/hdr/mme/mme.h index 84db27013..ef9fd6d00 100644 --- a/srsepc/hdr/mme/mme.h +++ b/srsepc/hdr/mme/mme.h @@ -28,13 +28,13 @@ #ifndef SRSEPC_MME_H #define SRSEPC_MME_H -#include +#include "s1ap.h" +#include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" -#include "srslte/common/logger_file.h" #include "srslte/common/log_filter.h" -#include "srslte/common/buffer_pool.h" +#include "srslte/common/logger_file.h" #include "srslte/common/threads.h" -#include "s1ap.h" +#include namespace srsepc { @@ -45,8 +45,8 @@ typedef struct { } mme_args_t; typedef struct { - int fd; - uint64_t imsi; + int fd; + uint64_t imsi; enum nas_timer_type type; } mme_timer_t; diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index 0e8b4d8cd..ffb7ebd25 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -76,7 +76,7 @@ private: int m_s11; struct sockaddr_un m_mme_addr, m_spgw_addr; - in_addr_t m_mme_gtpc_ip; + in_addr_t m_mme_gtpc_ip; bool init_s11(); uint32_t get_new_ctrl_teid(); diff --git a/srsepc/hdr/mme/nas.h b/srsepc/hdr/mme/nas.h index 70f2f0853..320a78b99 100644 --- a/srsepc/hdr/mme/nas.h +++ b/srsepc/hdr/mme/nas.h @@ -42,7 +42,9 @@ typedef enum { EMM_STATE_DEREGISTERED_INITIATED, EMM_STATE_N_ITEMS, } emm_state_t; -static const char emm_state_text[EMM_STATE_N_ITEMS][100] = {"DEREGISTERED", "COMMON PROCEDURE INITIATED", "REGISTERED", +static const char emm_state_text[EMM_STATE_N_ITEMS][100] = {"DEREGISTERED", + "COMMON PROCEDURE INITIATED", + "REGISTERED", "DEREGISTERED INITIATED"}; // MME ECM states (3GPP 23.401 v10.0.0, section 4.6.3) diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index c2112e808..dbefe080a 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -22,16 +22,16 @@ #ifndef SRSEPC_S1AP_COMMON_H #define SRSEPC_S1AP_COMMON_H -#include "srslte/common/security.h" #include "srslte/asn1/gtpc_ies.h" -#include "srslte/asn1/liblte_s1ap.h" #include "srslte/asn1/liblte_mme.h" +#include "srslte/asn1/liblte_s1ap.h" +#include "srslte/common/security.h" #include -namespace srsepc{ +namespace srsepc { -static const uint8_t MAX_TA=255; //Maximum TA supported -static const uint8_t MAX_BPLMN=6; //Maximum broadcasted PLMNs per TAC +static const uint8_t MAX_TA = 255; // Maximum TA supported +static const uint8_t MAX_BPLMN = 6; // Maximum broadcasted PLMNs per TAC typedef struct { uint8_t mme_code; @@ -50,20 +50,20 @@ typedef struct { srslte::INTEGRITY_ALGORITHM_ID_ENUM integrity_algo; } s1ap_args_t; -typedef struct{ - bool enb_name_present; - uint32_t enb_id; - uint8_t enb_name[150]; - uint16_t mcc, mnc; - uint32_t plmn; - uint8_t nof_supported_ta; - uint16_t tac[MAX_TA]; - uint8_t nof_supported_bplmns[MAX_TA]; - uint16_t bplmns[MAX_TA][MAX_BPLMN]; +typedef struct { + bool enb_name_present; + uint32_t enb_id; + uint8_t enb_name[150]; + uint16_t mcc, mnc; + uint32_t plmn; + uint8_t nof_supported_ta; + uint16_t tac[MAX_TA]; + uint8_t nof_supported_bplmns[MAX_TA]; + uint16_t bplmns[MAX_TA][MAX_BPLMN]; LIBLTE_S1AP_PAGINGDRX_ENUM drx; - struct sctp_sndrcvinfo sri; + struct sctp_sndrcvinfo sri; } enb_ctx_t; -}//namespace +} // namespace srsepc #endif // SRSEPC_S1AP_COMMON_H diff --git a/srsepc/hdr/mme/s1ap_mngmt_proc.h b/srsepc/hdr/mme/s1ap_mngmt_proc.h index da4d21a17..b7796708f 100644 --- a/srsepc/hdr/mme/s1ap_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_mngmt_proc.h @@ -21,29 +21,31 @@ #ifndef SRSEPC_S1AP_MNGMT_PROC_H #define SRSEPC_S1AP_MNGMT_PROC_H +#include "s1ap_common.h" #include "srslte/asn1/liblte_s1ap.h" #include "srslte/common/common.h" -#include "s1ap_common.h" #include "srslte/common/log_filter.h" -namespace srsepc{ +namespace srsepc { class s1ap; class s1ap_mngmt_proc { public: - - static s1ap_mngmt_proc *m_instance; + static s1ap_mngmt_proc* m_instance; static s1ap_mngmt_proc* get_instance(void); - static void cleanup(void); - void init(void); + static void cleanup(void); + void init(void); - bool handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); + bool handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT* msg, + sctp_sndrcvinfo* enb_sri, + srslte::byte_buffer_t* reply_buffer, + bool* reply_flag); - //Packing/unpacking helper functions - bool unpack_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, enb_ctx_t* enb_ctx); + // Packing/unpacking helper functions + bool unpack_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT* msg, enb_ctx_t* enb_ctx); bool pack_s1_setup_failure(LIBLTE_S1AP_CAUSEMISC_ENUM cause, srslte::byte_buffer_t* msg); bool pack_s1_setup_response(s1ap_args_t s1ap_args, srslte::byte_buffer_t* msg); @@ -51,13 +53,13 @@ private: s1ap_mngmt_proc(); virtual ~s1ap_mngmt_proc(); - s1ap* m_s1ap; - srslte::log_filter *m_s1ap_log; + s1ap* m_s1ap; + srslte::log_filter* m_s1ap_log; - int m_s1mme; + int m_s1mme; s1ap_args_t m_s1ap_args; }; -} //namespace srsepc +} // namespace srsepc #endif // SRSEPC_S1AP_MNGMT_PROC_H diff --git a/srsepc/hdr/spgw/gtpc.h b/srsepc/hdr/spgw/gtpc.h index 7002337a5..6e47fbf78 100644 --- a/srsepc/hdr/spgw/gtpc.h +++ b/srsepc/hdr/spgw/gtpc.h @@ -64,7 +64,8 @@ public: handle_downlink_data_notification_acknowledge(const srslte::gtpc_header& header, const srslte::gtpc_downlink_data_notification_acknowledge& not_ack); void handle_downlink_data_notification_failure_indication( - const srslte::gtpc_header& header, const srslte::gtpc_downlink_data_notification_failure_indication& not_fail); + const srslte::gtpc_header& header, + const srslte::gtpc_downlink_data_notification_failure_indication& not_fail); virtual bool queue_downlink_packet(uint32_t spgw_ctr_teid, srslte::byte_buffer_t* msg); virtual bool send_downlink_data_notification(uint32_t spgw_ctr_teid); diff --git a/srsepc/hdr/spgw/gtpu.h b/srsepc/hdr/spgw/gtpu.h index 1ce202467..3f396d277 100644 --- a/srsepc/hdr/spgw/gtpu.h +++ b/srsepc/hdr/spgw/gtpu.h @@ -92,6 +92,5 @@ inline in_addr_t spgw::gtpu::get_s1u_addr() return m_s1u_addr.sin_addr.s_addr; } - } // namespace srsepc #endif // SRSEPC_GTPU_H diff --git a/srsepc/hdr/spgw/spgw.h b/srsepc/hdr/spgw/spgw.h index 27bf2a741..a44dcecc8 100644 --- a/srsepc/hdr/spgw/spgw.h +++ b/srsepc/hdr/spgw/spgw.h @@ -75,8 +75,8 @@ public: srslte::log_filter* gtpc_log, srslte::log_filter* spgw_log, const std::map& ip_to_imsi); - void stop(); - void run_thread(); + void stop(); + void run_thread(); private: spgw(); diff --git a/srsepc/src/hss/hss.cc b/srsepc/src/hss/hss.cc index 1df484802..d16bf8a8e 100644 --- a/srsepc/src/hss/hss.cc +++ b/srsepc/src/hss/hss.cc @@ -79,8 +79,7 @@ int hss::init(hss_args_t* hss_args, srslte::log_filter* hss_log) db_file = hss_args->db_file; - m_hss_log->info("HSS Initialized. DB file %s, MCC: %d, MNC: %d\n", - hss_args->db_file.c_str(), mcc, mnc); + m_hss_log->info("HSS Initialized. DB file %s, MCC: %d, MNC: %d\n", hss_args->db_file.c_str(), mcc, mnc); m_hss_log->console("HSS Initialized.\n"); return 0; } @@ -132,7 +131,7 @@ bool hss::read_db_file(std::string db_filename) m_hss_log->error("Neither XOR nor MILENAGE configured.\n"); return false; } - ue_ctx->imsi = atoll(split[2].c_str()); + ue_ctx->imsi = atoll(split[2].c_str()); get_uint_vec_from_hex_str(split[3], ue_ctx->key, 16); if (split[4] == std::string("op")) { ue_ctx->op_configured = true; @@ -203,7 +202,7 @@ bool hss::write_db_file(std::string db_filename) } m_hss_log->info("Opened DB file: %s\n", db_filename.c_str()); - //Write comment info + // Write comment info m_db_file << "# \n" << "# .csv to store UE's information in HSS \n" << "# Kept in the following format: \"Name,Auth,IMSI,Key,OP_Type,OP,AMF,SQN,QCI,IP_alloc\" \n" diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index 966ff4d21..ac035bb4f 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -101,6 +101,7 @@ void parse_args(all_args_t* args, int argc, char* argv[]) // Command line only options bpo::options_description general("General options"); + // clang-format off general.add_options() ("help,h", "Produce help message") ("version,v", "Print version information and exit") @@ -108,7 +109,6 @@ void parse_args(all_args_t* args, int argc, char* argv[]) // Command line or config file options bpo::options_description common("Configuration options"); - // clang-format off common.add_options() ("mme.mme_code", bpo::value(&mme_code)->default_value("0x01"), "MME Code") ("mme.name", bpo::value(&mme_name)->default_value("srsmme01"), "MME Name") @@ -151,7 +151,6 @@ void parse_args(all_args_t* args, int argc, char* argv[]) ("log.filename", bpo::value(&args->log_args.filename)->default_value("/tmp/epc.log"),"Log filename") ; - // clang-format on // Positional options - config file location bpo::options_description position("Positional options"); @@ -208,7 +207,7 @@ void parse_args(all_args_t* args, int argc, char* argv[]) exit(1); } - //Concert hex strings + // Concert hex strings { std::stringstream sstr; sstr << std::hex << vm["mme.mme_group"].as(); diff --git a/srsepc/src/mbms-gw/main.cc b/srsepc/src/mbms-gw/main.cc index 309cc7e0a..da024c342 100644 --- a/srsepc/src/mbms-gw/main.cc +++ b/srsepc/src/mbms-gw/main.cc @@ -18,14 +18,14 @@ * and at http://www.gnu.org/licenses/. * */ -#include -#include +#include "srsepc/hdr/mbms-gw/mbms-gw.h" +#include "srslte/common/config_file.h" +#include +#include #include +#include +#include #include -#include -#include -#include "srslte/common/config_file.h" -#include "srsepc/hdr/mbms-gw/mbms-gw.h" using namespace std; using namespace srsepc; @@ -33,39 +33,38 @@ namespace bpo = boost::program_options; bool running = true; -void -sig_int_handler(int signo){ +void sig_int_handler(int signo) +{ running = false; } typedef struct { - std::string mbms_gw_level; - int mbms_gw_hex_limit; - std::string all_level; - int all_hex_limit; - std::string filename; -}log_args_t; + std::string mbms_gw_level; + int mbms_gw_hex_limit; + std::string all_level; + int all_hex_limit; + std::string filename; +} log_args_t; typedef struct { mbms_gw_args_t mbms_gw_args; log_args_t log_args; -}all_args_t; +} all_args_t; -srslte::LOG_LEVEL_ENUM -level(std::string l) +srslte::LOG_LEVEL_ENUM level(std::string l) { boost::to_upper(l); - if("NONE" == l){ + if ("NONE" == l) { return srslte::LOG_LEVEL_NONE; - }else if("ERROR" == l){ + } else if ("ERROR" == l) { return srslte::LOG_LEVEL_ERROR; - }else if("WARNING" == l){ + } else if ("WARNING" == l) { return srslte::LOG_LEVEL_WARNING; - }else if("INFO" == l){ + } else if ("INFO" == l) { return srslte::LOG_LEVEL_INFO; - }else if("DEBUG" == l){ + } else if ("DEBUG" == l) { return srslte::LOG_LEVEL_DEBUG; - }else{ + } else { return srslte::LOG_LEVEL_NONE; } } @@ -75,8 +74,8 @@ level(std::string l) ***********************************************************************/ string config_file; -void -parse_args(all_args_t *args, int argc, char* argv[]) { +void parse_args(all_args_t* args, int argc, char* argv[]) +{ string mbms_gw_name; string mbms_gw_sgi_mb_if_name; @@ -89,6 +88,8 @@ parse_args(all_args_t *args, int argc, char* argv[]) { // Command line only options bpo::options_description general("General options"); + + // clang-format off general.add_options() ("help,h", "Produce help message") ("version,v", "Print version information and exit") @@ -117,28 +118,30 @@ parse_args(all_args_t *args, int argc, char* argv[]) { position.add_options() ("config_file", bpo::value< string >(&config_file), "MBMS-GW configuration file") ; + + // clang-format on bpo::positional_options_description p; p.add("config_file", -1); // these options are allowed on the command line bpo::options_description cmdline_options; - cmdline_options.add(common).add(position).add(general); + cmdline_options.add(common).add(position).add(general); // parse the command line and store result in vm bpo::variables_map vm; try { bpo::store(bpo::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm); bpo::notify(vm); - } catch(bpo::error &e) { - cerr<< e.what() << endl; + } catch (bpo::error& e) { + cerr << e.what() << endl; exit(1); } // help option was given - print usage and exit if (vm.count("help")) { - cout << "Usage: " << argv[0] << " [OPTIONS] config_file" << endl << endl; - cout << common << endl << general << endl; - exit(0); + cout << "Usage: " << argv[0] << " [OPTIONS] config_file" << endl << endl; + cout << common << endl << general << endl; + exit(0); } // if no config file given, check users home path @@ -149,17 +152,17 @@ parse_args(all_args_t *args, int argc, char* argv[]) { } } - //Parsing Config File + // Parsing Config File cout << "Reading configuration file " << config_file << "..." << endl; ifstream conf(config_file.c_str(), ios::in); - if(conf.fail()) { + if (conf.fail()) { cout << "Failed to read configuration file " << config_file << " - exiting" << endl; exit(1); } bpo::store(bpo::parse_config_file(conf, common), vm); bpo::notify(vm); - args->mbms_gw_args.name = mbms_gw_name; + args->mbms_gw_args.name = mbms_gw_name; args->mbms_gw_args.sgi_mb_if_name = mbms_gw_sgi_mb_if_name; args->mbms_gw_args.sgi_mb_if_addr = mbms_gw_sgi_mb_if_addr; args->mbms_gw_args.sgi_mb_if_mask = mbms_gw_sgi_mb_if_mask; @@ -168,36 +171,33 @@ parse_args(all_args_t *args, int argc, char* argv[]) { // Apply all_level to any unset layers if (vm.count("log.all_level")) { - if(!vm.count("log.mbms_gw_level")) { + if (!vm.count("log.mbms_gw_level")) { args->log_args.mbms_gw_level = args->log_args.all_level; } } // Apply all_hex_limit to any unset layers if (vm.count("log.all_hex_limit")) { - if(!vm.count("log.mbms_gw_hex_limit")) { + if (!vm.count("log.mbms_gw_hex_limit")) { args->log_args.mbms_gw_hex_limit = args->log_args.all_hex_limit; } } return; } - - -int -main (int argc,char * argv[] ) +int main(int argc, char* argv[]) { - cout << endl <<"--- Software Radio Systems MBMS ---" << endl << endl; + cout << endl << "--- Software Radio Systems MBMS ---" << endl << endl; signal(SIGINT, sig_int_handler); signal(SIGTERM, sig_int_handler); signal(SIGKILL, sig_int_handler); all_args_t args; - parse_args(&args, argc, argv); + parse_args(&args, argc, argv); srslte::logger_stdout logger_stdout; srslte::logger_file logger_file; - srslte::logger *logger; + srslte::logger* logger; /*Init logger*/ if (!args.log_args.filename.compare("stdout")) { @@ -209,24 +209,24 @@ main (int argc,char * argv[] ) } srslte::log_filter mbms_gw_log; - mbms_gw_log.init("MBMS",logger); + mbms_gw_log.init("MBMS", logger); mbms_gw_log.set_level(level(args.log_args.mbms_gw_level)); mbms_gw_log.set_hex_limit(args.log_args.mbms_gw_hex_limit); - mbms_gw *mbms_gw = mbms_gw::get_instance(); - if(mbms_gw->init(&args.mbms_gw_args,&mbms_gw_log)) { + mbms_gw* mbms_gw = mbms_gw::get_instance(); + if (mbms_gw->init(&args.mbms_gw_args, &mbms_gw_log)) { cout << "Error initializing MBMS-GW" << endl; exit(1); - } + } - mbms_gw->start(); - while(running) { + mbms_gw->start(); + while (running) { sleep(1); } mbms_gw->stop(); mbms_gw->cleanup(); - cout << std::endl <<"--- exiting ---" << endl; + cout << std::endl << "--- exiting ---" << endl; return 0; } diff --git a/srsepc/src/mbms-gw/mbms-gw.cc b/srsepc/src/mbms-gw/mbms-gw.cc index f498809ba..c2b5d01d3 100644 --- a/srsepc/src/mbms-gw/mbms-gw.cc +++ b/srsepc/src/mbms-gw/mbms-gw.cc @@ -19,22 +19,22 @@ * */ -#include +#include "srsepc/hdr/mbms-gw/mbms-gw.h" +#include "srslte/upper/gtpu.h" #include #include -#include -#include -#include +#include #include #include -#include #include -#include "srsepc/hdr/mbms-gw/mbms-gw.h" -#include "srslte/upper/gtpu.h" +#include +#include +#include +#include -namespace srsepc{ +namespace srsepc { -mbms_gw* mbms_gw::m_instance = NULL; +mbms_gw* mbms_gw::m_instance = NULL; pthread_mutex_t mbms_gw_instance_mutex = PTHREAD_MUTEX_INITIALIZER; const uint16_t MBMS_GW_BUFFER_SIZE = 2500; @@ -49,47 +49,42 @@ mbms_gw::~mbms_gw() return; } -mbms_gw* -mbms_gw::get_instance(void) +mbms_gw* mbms_gw::get_instance(void) { pthread_mutex_lock(&mbms_gw_instance_mutex); - if(NULL == m_instance) { + if (NULL == m_instance) { m_instance = new mbms_gw(); } pthread_mutex_unlock(&mbms_gw_instance_mutex); - return(m_instance); + return (m_instance); } -void -mbms_gw::cleanup(void) +void mbms_gw::cleanup(void) { pthread_mutex_lock(&mbms_gw_instance_mutex); - if(NULL != m_instance) { + if (NULL != m_instance) { delete m_instance; m_instance = NULL; } pthread_mutex_unlock(&mbms_gw_instance_mutex); } -int -mbms_gw::init(mbms_gw_args_t* args, srslte::log_filter *mbms_gw_log) +int mbms_gw::init(mbms_gw_args_t* args, srslte::log_filter* mbms_gw_log) { int err; m_pool = srslte::byte_buffer_pool::get_instance(); - //Init log + // Init log m_mbms_gw_log = mbms_gw_log; err = init_sgi_mb_if(args); - if (err != SRSLTE_SUCCESS) - { + if (err != SRSLTE_SUCCESS) { m_mbms_gw_log->console("Error initializing SGi-MB.\n"); m_mbms_gw_log->error("Error initializing SGi-MB.\n"); return SRSLTE_ERROR_CANT_START; } err = init_m1_u(args); - if (err != SRSLTE_SUCCESS) - { + if (err != SRSLTE_SUCCESS) { m_mbms_gw_log->console("Error initializing SGi-MB.\n"); m_mbms_gw_log->error("Error initializing SGi-MB.\n"); return SRSLTE_ERROR_CANT_START; @@ -99,13 +94,10 @@ mbms_gw::init(mbms_gw_args_t* args, srslte::log_filter *mbms_gw_log) return SRSLTE_SUCCESS; } -void -mbms_gw::stop() +void mbms_gw::stop() { - if(m_running) - { - if(m_sgi_mb_up) - { + if (m_running) { + if (m_sgi_mb_up) { close(m_sgi_mb_if); m_mbms_gw_log->info("Closed SGi-MB interface\n"); } @@ -116,29 +108,28 @@ mbms_gw::stop() return; } -int -mbms_gw::init_sgi_mb_if(mbms_gw_args_t *args) +int mbms_gw::init_sgi_mb_if(mbms_gw_args_t* args) { struct ifreq ifr; - if(m_sgi_mb_up) - { + if (m_sgi_mb_up) { return SRSLTE_ERROR_ALREADY_STARTED; } - // Construct the TUN device m_sgi_mb_if = open("/dev/net/tun", O_RDWR); m_mbms_gw_log->info("TUN file descriptor = %d\n", m_sgi_mb_if); if (m_sgi_mb_if < 0) { - m_mbms_gw_log->error("Failed to open TUN device: %s\n", strerror(errno)); - return SRSLTE_ERROR_CANT_START; + m_mbms_gw_log->error("Failed to open TUN device: %s\n", strerror(errno)); + return SRSLTE_ERROR_CANT_START; } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TUN | IFF_NO_PI; - strncpy(ifr.ifr_ifrn.ifrn_name, args->sgi_mb_if_name.c_str(), std::min(args->sgi_mb_if_name.length(), (size_t)IFNAMSIZ-1) ); - ifr.ifr_ifrn.ifrn_name[IFNAMSIZ-1]='\0'; + strncpy(ifr.ifr_ifrn.ifrn_name, + args->sgi_mb_if_name.c_str(), + std::min(args->sgi_mb_if_name.length(), (size_t)IFNAMSIZ - 1)); + ifr.ifr_ifrn.ifrn_name[IFNAMSIZ - 1] = '\0'; if (ioctl(m_sgi_mb_if, TUNSETIFF, &ifr) < 0) { m_mbms_gw_log->error("Failed to set TUN device name: %s\n", strerror(errno)); @@ -150,45 +141,43 @@ mbms_gw::init_sgi_mb_if(mbms_gw_args_t *args) // Bring up the interface int sgi_mb_sock = socket(AF_INET, SOCK_DGRAM, 0); - if(sgi_mb_sock<0) - { + if (sgi_mb_sock < 0) { m_mbms_gw_log->error("Failed to bring up socket: %s\n", strerror(errno)); close(m_sgi_mb_if); return SRSLTE_ERROR_CANT_START; } - if(ioctl(sgi_mb_sock, SIOCGIFFLAGS, &ifr) < 0) - { - m_mbms_gw_log->error("Failed to bring up interface: %s\n", strerror(errno)); - close(m_sgi_mb_if); - close(sgi_mb_sock); - return SRSLTE_ERROR_CANT_START; + if (ioctl(sgi_mb_sock, SIOCGIFFLAGS, &ifr) < 0) { + m_mbms_gw_log->error("Failed to bring up interface: %s\n", strerror(errno)); + close(m_sgi_mb_if); + close(sgi_mb_sock); + return SRSLTE_ERROR_CANT_START; } ifr.ifr_flags |= IFF_UP | IFF_RUNNING; - if(ioctl(sgi_mb_sock, SIOCSIFFLAGS, &ifr) < 0) - { - m_mbms_gw_log->error("Failed to set socket flags: %s\n", strerror(errno)); - close(sgi_mb_sock); - close(m_sgi_mb_if); - return SRSLTE_ERROR_CANT_START; + if (ioctl(sgi_mb_sock, SIOCSIFFLAGS, &ifr) < 0) { + m_mbms_gw_log->error("Failed to set socket flags: %s\n", strerror(errno)); + close(sgi_mb_sock); + close(m_sgi_mb_if); + return SRSLTE_ERROR_CANT_START; } - //Set IP of the interface - struct sockaddr_in *addr = (struct sockaddr_in*)&ifr.ifr_addr; - addr->sin_family = AF_INET; - addr->sin_addr.s_addr = inet_addr(args->sgi_mb_if_addr.c_str()); - addr->sin_port = 0; + // Set IP of the interface + struct sockaddr_in* addr = (struct sockaddr_in*)&ifr.ifr_addr; + addr->sin_family = AF_INET; + addr->sin_addr.s_addr = inet_addr(args->sgi_mb_if_addr.c_str()); + addr->sin_port = 0; if (ioctl(sgi_mb_sock, SIOCSIFADDR, &ifr) < 0) { - m_mbms_gw_log->error("Failed to set TUN interface IP. Address: %s, Error: %s\n", args->sgi_mb_if_addr.c_str(), strerror(errno)); + m_mbms_gw_log->error( + "Failed to set TUN interface IP. Address: %s, Error: %s\n", args->sgi_mb_if_addr.c_str(), strerror(errno)); close(m_sgi_mb_if); close(sgi_mb_sock); return SRSLTE_ERROR_CANT_START; } - ifr.ifr_netmask.sa_family = AF_INET; - ((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr(args->sgi_mb_if_mask.c_str()); + ifr.ifr_netmask.sa_family = AF_INET; + ((struct sockaddr_in*)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr(args->sgi_mb_if_mask.c_str()); if (ioctl(sgi_mb_sock, SIOCSIFNETMASK, &ifr) < 0) { m_mbms_gw_log->error("Failed to set TUN interface Netmask. Error: %s\n", strerror(errno)); close(m_sgi_mb_if); @@ -247,28 +236,24 @@ int mbms_gw::init_m1_u(mbms_gw_args_t* args) return SRSLTE_SUCCESS; } -void -mbms_gw::run_thread() +void mbms_gw::run_thread() { - //Mark the thread as running - m_running=true; - srslte::byte_buffer_t *msg; + // Mark the thread as running + m_running = true; + srslte::byte_buffer_t* msg; msg = m_pool->allocate(); - uint8_t seq = 0; - while(m_running) - { + while (m_running) { msg->clear(); int n; - do{ + do { n = read(m_sgi_mb_if, msg->msg, SRSLTE_MAX_BUFFER_SIZE_BYTES); - }while(n == -1 && errno == EAGAIN); + } while (n == -1 && errno == EAGAIN); - if(n<0){ + if (n < 0) { m_mbms_gw_log->error("Error reading from TUN interface. Error: %s\n", strerror(errno)); - } - else{ + } else { msg->N_bytes = n; handle_sgi_md_pdu(msg); } @@ -277,44 +262,41 @@ mbms_gw::run_thread() return; } -void -mbms_gw::handle_sgi_md_pdu(srslte::byte_buffer_t *msg) +void mbms_gw::handle_sgi_md_pdu(srslte::byte_buffer_t* msg) { - uint8_t version; + uint8_t version; srslte::gtpu_header_t header; - //Setup GTP-U header + // Setup GTP-U header header.flags = GTPU_FLAGS_VERSION_V1 | GTPU_FLAGS_GTP_PROTOCOL; header.message_type = GTPU_MSG_DATA_PDU; header.length = msg->N_bytes; - header.teid = 0xAAAA; //FIXME Harcoded TEID for now + header.teid = 0xAAAA; // FIXME Harcoded TEID for now - //Sanity Check IP packet + // Sanity Check IP packet if (msg->N_bytes < 20) { m_mbms_gw_log->error("IPv4 min len: %d, drop msg len %d\n", 20, msg->N_bytes); return; } - //IP Headers - struct iphdr *iph = (struct iphdr *) msg->msg; - if(iph->version != 4) { + // IP Headers + struct iphdr* iph = (struct iphdr*)msg->msg; + if (iph->version != 4) { m_mbms_gw_log->warning("IPv6 not supported yet.\n"); return; } - //Write GTP-U header into packet + // Write GTP-U header into packet if (!srslte::gtpu_write_header(&header, msg, m_mbms_gw_log)) { m_mbms_gw_log->console("Error writing GTP-U header on PDU\n"); } - int n = sendto(m_m1u, msg->msg, msg->N_bytes, 0, - (sockaddr *) &m_m1u_multi_addr, sizeof(struct sockaddr)); - if(n<0){ + int n = sendto(m_m1u, msg->msg, msg->N_bytes, 0, (sockaddr*)&m_m1u_multi_addr, sizeof(struct sockaddr)); + if (n < 0) { m_mbms_gw_log->console("Error writing to M1-U socket.\n"); - } - else{ + } else { m_mbms_gw_log->debug("Sent %d Bytes\n", msg->N_bytes); } } -} //namespace srsepc +} // namespace srsepc diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 3c8a07763..f7b9245ec 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -177,7 +177,7 @@ bool mme_gtpc::send_create_session_request(uint64_t imsi) cs_req_pdu.header.piggyback = false; cs_req_pdu.header.teid_present = true; cs_req_pdu.header.teid = 0; // Send create session request to the butler TEID - cs_req_pdu.header.type = srslte::GTPC_MSG_TYPE_CREATE_SESSION_REQUEST; + cs_req_pdu.header.type = srslte::GTPC_MSG_TYPE_CREATE_SESSION_REQUEST; // Setup GTP-C Create Session Request IEs cs_req->imsi = imsi; @@ -259,7 +259,7 @@ bool mme_gtpc::handle_create_session_response(srslte::gtpc_pdu* cs_resp_pdu) // Get S-GW Control F-TEID srslte::gtp_fteid_t sgw_ctr_fteid = {}; - sgw_ctr_fteid.teid = cs_resp_pdu->header.teid; + sgw_ctr_fteid.teid = cs_resp_pdu->header.teid; sgw_ctr_fteid.ipv4 = 0; // FIXME This is not used for now. In the future it will be obtained from the socket addr_info // Get S-GW S1-u F-TEID diff --git a/srsepc/src/mme/nas.cc b/srsepc/src/mme/nas.cc index 03942d934..94fcd90c8 100644 --- a/srsepc/src/mme/nas.cc +++ b/srsepc/src/mme/nas.cc @@ -59,9 +59,9 @@ void nas::reset() srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo = m_sec_ctx.integ_algo; srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo = m_sec_ctx.cipher_algo; - m_sec_ctx = {}; - m_sec_ctx.integ_algo = integ_algo; - m_sec_ctx.cipher_algo = cipher_algo; + m_sec_ctx = {}; + m_sec_ctx.integ_algo = integ_algo; + m_sec_ctx.cipher_algo = cipher_algo; } /********************************** @@ -122,20 +122,40 @@ bool nas::handle_attach_request(uint32_t enb_ue_s1ap_id, nas_log->console("Attach request -- Attach type: %d\n", attach_req.eps_attach_type); nas_log->info("Attach request -- Attach type: %d\n", attach_req.eps_attach_type); nas_log->console("Attach Request -- UE Network Capabilities EEA: %d%d%d%d%d%d%d%d\n", - attach_req.ue_network_cap.eea[0], attach_req.ue_network_cap.eea[1], attach_req.ue_network_cap.eea[2], - attach_req.ue_network_cap.eea[3], attach_req.ue_network_cap.eea[4], attach_req.ue_network_cap.eea[5], - attach_req.ue_network_cap.eea[6], attach_req.ue_network_cap.eea[7]); - nas_log->info("Attach Request -- UE Network Capabilities EEA: %d%d%d%d%d%d%d%d\n", attach_req.ue_network_cap.eea[0], - attach_req.ue_network_cap.eea[1], attach_req.ue_network_cap.eea[2], attach_req.ue_network_cap.eea[3], - attach_req.ue_network_cap.eea[4], attach_req.ue_network_cap.eea[5], attach_req.ue_network_cap.eea[6], + attach_req.ue_network_cap.eea[0], + attach_req.ue_network_cap.eea[1], + attach_req.ue_network_cap.eea[2], + attach_req.ue_network_cap.eea[3], + attach_req.ue_network_cap.eea[4], + attach_req.ue_network_cap.eea[5], + attach_req.ue_network_cap.eea[6], + attach_req.ue_network_cap.eea[7]); + nas_log->info("Attach Request -- UE Network Capabilities EEA: %d%d%d%d%d%d%d%d\n", + attach_req.ue_network_cap.eea[0], + attach_req.ue_network_cap.eea[1], + attach_req.ue_network_cap.eea[2], + attach_req.ue_network_cap.eea[3], + attach_req.ue_network_cap.eea[4], + attach_req.ue_network_cap.eea[5], + attach_req.ue_network_cap.eea[6], attach_req.ue_network_cap.eea[7]); nas_log->console("Attach Request -- UE Network Capabilities EIA: %d%d%d%d%d%d%d%d\n", - attach_req.ue_network_cap.eia[0], attach_req.ue_network_cap.eia[1], attach_req.ue_network_cap.eia[2], - attach_req.ue_network_cap.eia[3], attach_req.ue_network_cap.eia[4], attach_req.ue_network_cap.eia[5], - attach_req.ue_network_cap.eia[6], attach_req.ue_network_cap.eia[7]); - nas_log->info("Attach Request -- UE Network Capabilities EIA: %d%d%d%d%d%d%d%d\n", attach_req.ue_network_cap.eia[0], - attach_req.ue_network_cap.eia[1], attach_req.ue_network_cap.eia[2], attach_req.ue_network_cap.eia[3], - attach_req.ue_network_cap.eia[4], attach_req.ue_network_cap.eia[5], attach_req.ue_network_cap.eia[6], + attach_req.ue_network_cap.eia[0], + attach_req.ue_network_cap.eia[1], + attach_req.ue_network_cap.eia[2], + attach_req.ue_network_cap.eia[3], + attach_req.ue_network_cap.eia[4], + attach_req.ue_network_cap.eia[5], + attach_req.ue_network_cap.eia[6], + attach_req.ue_network_cap.eia[7]); + nas_log->info("Attach Request -- UE Network Capabilities EIA: %d%d%d%d%d%d%d%d\n", + attach_req.ue_network_cap.eia[0], + attach_req.ue_network_cap.eia[1], + attach_req.ue_network_cap.eia[2], + attach_req.ue_network_cap.eia[3], + attach_req.ue_network_cap.eia[4], + attach_req.ue_network_cap.eia[5], + attach_req.ue_network_cap.eia[6], attach_req.ue_network_cap.eia[7]); nas_log->console("Attach Request -- MS Network Capabilities Present: %s\n", attach_req.ms_network_cap_present ? "true" : "false"); @@ -165,11 +185,11 @@ bool nas::handle_attach_request(uint32_t enb_ue_s1ap_id, nas_log->info("Attach Request -- Found previously attached UE.\n"); nas_log->console("Attach Request -- Found previously attach UE.\n"); if (attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMSI) { - nas::handle_imsi_attach_request_known_ue(nas_ctx, enb_ue_s1ap_id, enb_sri, attach_req, pdn_con_req, nas_rx, args, - itf, nas_log); + nas::handle_imsi_attach_request_known_ue( + nas_ctx, enb_ue_s1ap_id, enb_sri, attach_req, pdn_con_req, nas_rx, args, itf, nas_log); } else if (attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_GUTI) { - nas::handle_guti_attach_request_known_ue(nas_ctx, enb_ue_s1ap_id, enb_sri, attach_req, pdn_con_req, nas_rx, args, - itf, nas_log); + nas::handle_guti_attach_request_known_ue( + nas_ctx, enb_ue_s1ap_id, enb_sri, attach_req, pdn_con_req, nas_rx, args, itf, nas_log); } else { return false; } @@ -210,11 +230,12 @@ bool nas::handle_imsi_attach_request_unknown_ue(uint32_t nas_ctx->m_ecm_ctx.mme_ue_s1ap_id = s1ap->get_next_mme_ue_s1ap_id(); // Save UE network capabilities - memcpy(&nas_ctx->m_sec_ctx.ue_network_cap, &attach_req.ue_network_cap, - sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); + memcpy( + &nas_ctx->m_sec_ctx.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); nas_ctx->m_sec_ctx.ms_network_cap_present = attach_req.ms_network_cap_present; if (attach_req.ms_network_cap_present) { - memcpy(&nas_ctx->m_sec_ctx.ms_network_cap, &attach_req.ms_network_cap, + memcpy(&nas_ctx->m_sec_ctx.ms_network_cap, + &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); } @@ -241,8 +262,11 @@ bool nas::handle_imsi_attach_request_unknown_ue(uint32_t nas_ctx->m_emm_ctx.attach_type = attach_req.eps_attach_type; // Get Authentication Vectors from HSS - if (!hss->gen_auth_info_answer(nas_ctx->m_emm_ctx.imsi, nas_ctx->m_sec_ctx.k_asme, nas_ctx->m_sec_ctx.autn, - nas_ctx->m_sec_ctx.rand, nas_ctx->m_sec_ctx.xres)) { + if (!hss->gen_auth_info_answer(nas_ctx->m_emm_ctx.imsi, + nas_ctx->m_sec_ctx.k_asme, + nas_ctx->m_sec_ctx.autn, + nas_ctx->m_sec_ctx.rand, + nas_ctx->m_sec_ctx.xres)) { nas_log->console("User not found. IMSI %015" PRIu64 "\n", nas_ctx->m_emm_ctx.imsi); nas_log->info("User not found. IMSI %015" PRIu64 "\n", nas_ctx->m_emm_ctx.imsi); delete nas_ctx; @@ -263,8 +287,8 @@ bool nas::handle_imsi_attach_request_unknown_ue(uint32_t nas_ctx->pack_authentication_request(nas_tx); // Send reply to eNB - s1ap->send_downlink_nas_transport(nas_ctx->m_ecm_ctx.enb_ue_s1ap_id, nas_ctx->m_ecm_ctx.mme_ue_s1ap_id, nas_tx, - nas_ctx->m_ecm_ctx.enb_sri); + s1ap->send_downlink_nas_transport( + nas_ctx->m_ecm_ctx.enb_ue_s1ap_id, nas_ctx->m_ecm_ctx.mme_ue_s1ap_id, nas_tx, nas_ctx->m_ecm_ctx.enb_sri); pool->deallocate(nas_tx); nas_log->info("Downlink NAS: Sending Authentication Request\n"); @@ -333,11 +357,12 @@ bool nas::handle_guti_attach_request_unknown_ue(uint32_t nas_ctx->m_emm_ctx.state = EMM_STATE_DEREGISTERED; // Save UE network capabilities - memcpy(&nas_ctx->m_sec_ctx.ue_network_cap, &attach_req.ue_network_cap, - sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); + memcpy( + &nas_ctx->m_sec_ctx.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); nas_ctx->m_sec_ctx.ms_network_cap_present = attach_req.ms_network_cap_present; if (attach_req.ms_network_cap_present) { - memcpy(&nas_ctx->m_sec_ctx.ms_network_cap, &attach_req.ms_network_cap, + memcpy(&nas_ctx->m_sec_ctx.ms_network_cap, + &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); } // Initialize NAS count @@ -373,8 +398,8 @@ bool nas::handle_guti_attach_request_unknown_ue(uint32_t // Send Identity Request nas_tx = pool->allocate(); nas_ctx->pack_identity_request(nas_tx); - s1ap->send_downlink_nas_transport(nas_ctx->m_ecm_ctx.enb_ue_s1ap_id, nas_ctx->m_ecm_ctx.mme_ue_s1ap_id, nas_tx, - nas_ctx->m_ecm_ctx.enb_sri); + s1ap->send_downlink_nas_transport( + nas_ctx->m_ecm_ctx.enb_ue_s1ap_id, nas_ctx->m_ecm_ctx.mme_ue_s1ap_id, nas_tx, nas_ctx->m_ecm_ctx.enb_sri); pool->deallocate(nas_tx); return true; @@ -404,15 +429,17 @@ bool nas::handle_guti_attach_request_known_ue(nas* gtpc_interface_nas* gtpc = itf.gtpc; nas_log->console("Found UE context. IMSI: %015" PRIu64 ", old eNB UE S1ap Id %d, old MME UE S1AP Id %d\n", - emm_ctx->imsi, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); + emm_ctx->imsi, + ecm_ctx->enb_ue_s1ap_id, + ecm_ctx->mme_ue_s1ap_id); // Check NAS integrity msg_valid = nas_ctx->integrity_check(nas_rx); if (msg_valid == true && emm_ctx->state == EMM_STATE_DEREGISTERED) { - nas_log->console("GUTI Attach -- NAS Integrity OK. UL count %d, DL count %d\n", sec_ctx->ul_nas_count, - sec_ctx->dl_nas_count); - nas_log->info("GUTI Attach -- NAS Integrity OK. UL count %d, DL count %d\n", sec_ctx->ul_nas_count, - sec_ctx->dl_nas_count); + nas_log->console( + "GUTI Attach -- NAS Integrity OK. UL count %d, DL count %d\n", sec_ctx->ul_nas_count, sec_ctx->dl_nas_count); + nas_log->info( + "GUTI Attach -- NAS Integrity OK. UL count %d, DL count %d\n", sec_ctx->ul_nas_count, sec_ctx->dl_nas_count); // Create new MME UE S1AP Identity ecm_ctx->mme_ue_s1ap_id = s1ap->get_next_mme_ue_s1ap_id(); @@ -571,7 +598,7 @@ bool nas::handle_service_request(uint32_t m_tmsi, nas_tmp.m_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; nas_tmp.m_ecm_ctx.mme_ue_s1ap_id = s1ap->get_next_mme_ue_s1ap_id(); - srslte::byte_buffer_t* nas_tx = pool->allocate(); + srslte::byte_buffer_t* nas_tx = pool->allocate(); nas_tmp.pack_service_reject(nas_tx, LIBLTE_MME_EMM_CAUSE_IMPLICITLY_DETACHED); s1ap->send_downlink_nas_transport(enb_ue_s1ap_id, nas_tmp.m_ecm_ctx.mme_ue_s1ap_id, nas_tx, *enb_sri); pool->deallocate(nas_tx); @@ -605,7 +632,8 @@ bool nas::handle_service_request(uint32_t m_tmsi, // Release previous context nas_log->info("Service Request -- Releasing previouse ECM context. eNB S1AP Id %d, MME UE S1AP Id %d\n", - ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); + ecm_ctx->enb_ue_s1ap_id, + ecm_ctx->mme_ue_s1ap_id); s1ap->send_ue_context_release_command(ecm_ctx->mme_ue_s1ap_id); s1ap->release_ue_ecm_ctx(ecm_ctx->mme_ue_s1ap_id); } @@ -657,7 +685,8 @@ bool nas::handle_service_request(uint32_t m_tmsi, // Release previous context nas_log->info("Service Request -- Releasing previouse ECM context. eNB S1AP Id %d, MME UE S1AP Id %d\n", - ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); + ecm_ctx->enb_ue_s1ap_id, + ecm_ctx->mme_ue_s1ap_id); s1ap->send_ue_context_release_command(ecm_ctx->mme_ue_s1ap_id); s1ap->release_ue_ecm_ctx(ecm_ctx->mme_ue_s1ap_id); } @@ -669,11 +698,11 @@ bool nas::handle_service_request(uint32_t m_tmsi, ecm_ctx->mme_ue_s1ap_id = s1ap->get_next_mme_ue_s1ap_id(); s1ap->add_nas_ctx_to_mme_ue_s1ap_id_map(nas_ctx); s1ap->add_ue_to_enb_set(enb_sri->sinfo_assoc_id, nas_ctx->m_ecm_ctx.mme_ue_s1ap_id); - srslte::byte_buffer_t *nas_tx = pool->allocate(); + srslte::byte_buffer_t* nas_tx = pool->allocate(); nas_ctx->pack_service_reject(nas_tx, LIBLTE_MME_EMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK); s1ap->send_downlink_nas_transport(ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id, nas_tx, *enb_sri); pool->deallocate(nas_tx); - + nas_log->console("Service Request -- Short MAC invalid. Sending service reject.\n"); nas_log->warning("Service Request -- Short MAC invalid. Sending service reject.\n"); nas_log->info("Service Reject -- eNB_UE_S1AP_ID %d MME_UE_S1AP_ID %d.\n", enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); @@ -829,18 +858,14 @@ bool nas::handle_attach_request(srslte::byte_buffer_t* nas_rx) } // Save IMSI, eNB UE S1AP Id, MME UE S1AP Id and make sure UE is EMM_DEREGISTERED - m_emm_ctx.imsi = imsi; - m_emm_ctx.state = EMM_STATE_DEREGISTERED; + m_emm_ctx.imsi = imsi; + m_emm_ctx.state = EMM_STATE_DEREGISTERED; // Save UE network capabilities - memcpy(&m_sec_ctx.ue_network_cap, - &attach_req.ue_network_cap, - sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); + memcpy(&m_sec_ctx.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); m_sec_ctx.ms_network_cap_present = attach_req.ms_network_cap_present; if (attach_req.ms_network_cap_present) { - memcpy(&m_sec_ctx.ms_network_cap, - &attach_req.ms_network_cap, - sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); + memcpy(&m_sec_ctx.ms_network_cap, &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); } uint8_t eps_bearer_id = pdn_con_req.eps_bearer_id; // TODO: Unused @@ -882,8 +907,7 @@ bool nas::handle_attach_request(srslte::byte_buffer_t* nas_rx) pack_authentication_request(nas_tx); // Send reply to eNB - m_s1ap->send_downlink_nas_transport( - m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id, nas_tx, m_ecm_ctx.enb_sri); + m_s1ap->send_downlink_nas_transport(m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id, nas_tx, m_ecm_ctx.enb_sri); m_pool->deallocate(nas_tx); m_nas_log->info("Downlink NAS: Sending Authentication Request\n"); @@ -1016,8 +1040,8 @@ bool nas::handle_attach_complete(srslte::byte_buffer_t* nas_rx) } if (m_emm_ctx.state == EMM_STATE_DEREGISTERED) { // Attach requested from attach request - m_gtpc->send_modify_bearer_request(m_emm_ctx.imsi, act_bearer.eps_bearer_id, - &m_esm_ctx[act_bearer.eps_bearer_id].enb_fteid); + m_gtpc->send_modify_bearer_request( + m_emm_ctx.imsi, act_bearer.eps_bearer_id, &m_esm_ctx[act_bearer.eps_bearer_id].enb_fteid); // Send reply to EMM Info to UE nas_tx = m_pool->allocate(); @@ -1165,8 +1189,8 @@ bool nas::handle_authentication_failure(srslte::byte_buffer_t* nas_rx) return false; } // Get Authentication Vectors from HSS - if (!m_hss->gen_auth_info_answer(m_emm_ctx.imsi, m_sec_ctx.k_asme, m_sec_ctx.autn, m_sec_ctx.rand, - m_sec_ctx.xres)) { + if (!m_hss->gen_auth_info_answer( + m_emm_ctx.imsi, m_sec_ctx.k_asme, m_sec_ctx.autn, m_sec_ctx.rand, m_sec_ctx.xres)) { m_nas_log->console("User not found. IMSI %015" PRIu64 "\n", m_emm_ctx.imsi); m_nas_log->info("User not found. IMSI %015" PRIu64 "\n", m_emm_ctx.imsi); return false; @@ -1180,8 +1204,8 @@ bool nas::handle_authentication_failure(srslte::byte_buffer_t* nas_rx) pack_authentication_request(nas_tx); // Send reply to eNB - m_s1ap->send_downlink_nas_transport(m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id, nas_tx, - m_ecm_ctx.enb_sri); + m_s1ap->send_downlink_nas_transport( + m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id, nas_tx, m_ecm_ctx.enb_sri); m_pool->deallocate(nas_tx); m_nas_log->info("Downlink NAS: Sent Authentication Request\n"); @@ -1279,16 +1303,16 @@ bool nas::pack_security_mode_command(srslte::byte_buffer_t* nas_buffer) sm_cmd.nonce_mme_present = false; uint8_t sec_hdr_type = 3; - LIBLTE_ERROR_ENUM err = liblte_mme_pack_security_mode_command_msg(&sm_cmd, sec_hdr_type, m_sec_ctx.dl_nas_count, - (LIBLTE_BYTE_MSG_STRUCT*)nas_buffer); + LIBLTE_ERROR_ENUM err = liblte_mme_pack_security_mode_command_msg( + &sm_cmd, sec_hdr_type, m_sec_ctx.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT*)nas_buffer); if (err != LIBLTE_SUCCESS) { m_nas_log->console("Error packing Authentication Request\n"); return false; } // Generate EPS security context - srslte::security_generate_k_nas(m_sec_ctx.k_asme, m_sec_ctx.cipher_algo, m_sec_ctx.integ_algo, m_sec_ctx.k_nas_enc, - m_sec_ctx.k_nas_int); + srslte::security_generate_k_nas( + m_sec_ctx.k_asme, m_sec_ctx.cipher_algo, m_sec_ctx.integ_algo, m_sec_ctx.k_nas_enc, m_sec_ctx.k_nas_int); m_nas_log->info_hex(m_sec_ctx.k_nas_enc, 32, "Key NAS Encryption (k_nas_enc)\n"); m_nas_log->info_hex(m_sec_ctx.k_nas_int, 32, "Key NAS Integrity (k_nas_int)\n"); @@ -1381,8 +1405,11 @@ bool nas::pack_attach_accept(srslte::byte_buffer_t* nas_buffer) attach_accept.guti.guti.mme_code = m_mme_code; attach_accept.guti.guti.m_tmsi = m_s1ap->allocate_m_tmsi(m_emm_ctx.imsi); m_nas_log->debug("Allocated GUTI: MCC %d, MNC %d, MME Group Id %d, MME Code 0x%x, M-TMSI 0x%x\n", - attach_accept.guti.guti.mcc, attach_accept.guti.guti.mnc, attach_accept.guti.guti.mme_group_id, - attach_accept.guti.guti.mme_code, attach_accept.guti.guti.m_tmsi); + attach_accept.guti.guti.mcc, + attach_accept.guti.guti.mnc, + attach_accept.guti.guti.mme_group_id, + attach_accept.guti.guti.mme_code, + attach_accept.guti.guti.m_tmsi); memcpy(&m_sec_ctx.guti, &attach_accept.guti, sizeof(LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT)); @@ -1445,8 +1472,8 @@ bool nas::pack_attach_accept(srslte::byte_buffer_t* nas_buffer) m_sec_ctx.dl_nas_count++; liblte_mme_pack_activate_default_eps_bearer_context_request_msg(&act_def_eps_bearer_context_req, &attach_accept.esm_msg); - liblte_mme_pack_attach_accept_msg(&attach_accept, sec_hdr_type, m_sec_ctx.dl_nas_count, - (LIBLTE_BYTE_MSG_STRUCT*)nas_buffer); + liblte_mme_pack_attach_accept_msg( + &attach_accept, sec_hdr_type, m_sec_ctx.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT*)nas_buffer); // Encrypt NAS message cipher_encrypt(nas_buffer); @@ -1494,8 +1521,8 @@ bool nas::pack_emm_information(srslte::byte_buffer_t* nas_buffer) uint8_t sec_hdr_type = LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED; m_sec_ctx.dl_nas_count++; - LIBLTE_ERROR_ENUM err = liblte_mme_pack_emm_information_msg(&emm_info, sec_hdr_type, m_sec_ctx.dl_nas_count, - (LIBLTE_BYTE_MSG_STRUCT*)nas_buffer); + LIBLTE_ERROR_ENUM err = liblte_mme_pack_emm_information_msg( + &emm_info, sec_hdr_type, m_sec_ctx.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT*)nas_buffer); if (err != LIBLTE_SUCCESS) { m_nas_log->error("Error packing EMM Information\n"); m_nas_log->console("Error packing EMM Information\n"); @@ -1524,8 +1551,8 @@ bool nas::pack_service_reject(srslte::byte_buffer_t* nas_buffer, uint8_t emm_cau service_rej.t3446 = 0; service_rej.emm_cause = emm_cause; - LIBLTE_ERROR_ENUM err = liblte_mme_pack_service_reject_msg(&service_rej, LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS, 0, - (LIBLTE_BYTE_MSG_STRUCT*)nas_buffer); + LIBLTE_ERROR_ENUM err = liblte_mme_pack_service_reject_msg( + &service_rej, LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS, 0, (LIBLTE_BYTE_MSG_STRUCT*)nas_buffer); if (err != LIBLTE_SUCCESS) { m_nas_log->error("Error packing Service Reject\n"); m_nas_log->console("Error packing Service Reject\n"); @@ -1588,13 +1615,19 @@ bool nas::short_integrity_check(srslte::byte_buffer_t* pdu) if (exp_mac[i + 2] != mac[i]) { m_nas_log->warning("Short integrity check failure. Local: count=%d, [%02x %02x %02x %02x], " "Received: count=%d, [%02x %02x]\n", - m_sec_ctx.ul_nas_count, exp_mac[0], exp_mac[1], exp_mac[2], exp_mac[3], pdu->msg[1] & 0x1F, - mac[0], mac[1]); + m_sec_ctx.ul_nas_count, + exp_mac[0], + exp_mac[1], + exp_mac[2], + exp_mac[3], + pdu->msg[1] & 0x1F, + mac[0], + mac[1]); return false; } } - m_nas_log->info("Integrity check ok. Local: count=%d, Received: count=%d\n", m_sec_ctx.ul_nas_count, - pdu->msg[1] & 0x1F); + m_nas_log->info( + "Integrity check ok. Local: count=%d, Received: count=%d\n", m_sec_ctx.ul_nas_count, pdu->msg[1] & 0x1F); return true; } @@ -1643,8 +1676,16 @@ bool nas::integrity_check(srslte::byte_buffer_t* pdu) m_nas_log->warning("Integrity check failure. Algorithm=EIA%d\n", (int)m_sec_ctx.integ_algo); m_nas_log->warning("UL Local: count=%d, MAC=[%02x %02x %02x %02x], " "Received: UL count=%d, MAC=[%02x %02x %02x %02x]\n", - m_sec_ctx.ul_nas_count, exp_mac[0], exp_mac[1], exp_mac[2], exp_mac[3], pdu->msg[5], mac[0], - mac[1], mac[2], mac[3]); + m_sec_ctx.ul_nas_count, + exp_mac[0], + exp_mac[1], + exp_mac[2], + exp_mac[3], + pdu->msg[5], + mac[0], + mac[1], + mac[2], + mac[3]); return false; } } @@ -1854,7 +1895,8 @@ bool nas::expire_t3413() return false; } // Send Paging Failure to the SPGW - m_gtpc->send_downlink_data_notification_failure_indication(m_emm_ctx.imsi, srslte::GTPC_CAUSE_VALUE_UE_NOT_RESPONDING); + m_gtpc->send_downlink_data_notification_failure_indication(m_emm_ctx.imsi, + srslte::GTPC_CAUSE_VALUE_UE_NOT_RESPONDING); return true; } diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index f6e5b1b67..acc5426c3 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -255,18 +255,18 @@ bool s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT* msg, break; case LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_INITIALUEMESSAGE: m_s1ap_log->info("Received Initial UE Message.\n"); - m_s1ap_nas_transport->handle_initial_ue_message(&msg->choice.InitialUEMessage, enb_sri, reply_buffer, - &reply_flag); + m_s1ap_nas_transport->handle_initial_ue_message( + &msg->choice.InitialUEMessage, enb_sri, reply_buffer, &reply_flag); break; case LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_UPLINKNASTRANSPORT: m_s1ap_log->info("Received Uplink NAS Transport Message.\n"); - m_s1ap_nas_transport->handle_uplink_nas_transport(&msg->choice.UplinkNASTransport, enb_sri, reply_buffer, - &reply_flag); + m_s1ap_nas_transport->handle_uplink_nas_transport( + &msg->choice.UplinkNASTransport, enb_sri, reply_buffer, &reply_flag); break; case LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_UECONTEXTRELEASEREQUEST: m_s1ap_log->info("Received UE Context Release Request Message.\n"); - m_s1ap_ctx_mngmt_proc->handle_ue_context_release_request(&msg->choice.UEContextReleaseRequest, enb_sri, - reply_buffer, &reply_flag); + m_s1ap_ctx_mngmt_proc->handle_ue_context_release_request( + &msg->choice.UEContextReleaseRequest, enb_sri, reply_buffer, &reply_flag); break; default: m_s1ap_log->error("Unhandled S1AP intiating message: %s\n", @@ -348,7 +348,7 @@ void s1ap::delete_enb_ctx(int32_t assoc_id) return; } -//UE Context Management +// UE Context Management bool s1ap::add_nas_ctx_to_imsi_map(nas* nas_ctx) { std::map::iterator ctx_it = m_imsi_to_nas_ctx.find(nas_ctx->m_emm_ctx.imsi); @@ -441,8 +441,8 @@ void s1ap::release_ues_ecm_ctx_in_enb(int32_t enb_assoc) emm_ctx_t* emm_ctx = &nas_ctx->second->m_emm_ctx; ecm_ctx_t* ecm_ctx = &nas_ctx->second->m_ecm_ctx; - m_s1ap_log->info("Releasing UE context. IMSI: %015" PRIu64 ", UE-MME S1AP Id: %d\n", emm_ctx->imsi, - ecm_ctx->mme_ue_s1ap_id); + m_s1ap_log->info( + "Releasing UE context. IMSI: %015" PRIu64 ", UE-MME S1AP Id: %d\n", emm_ctx->imsi, ecm_ctx->mme_ue_s1ap_id); if (emm_ctx->state == EMM_STATE_REGISTERED) { m_mme_gtpc->send_delete_session_request(emm_ctx->imsi); emm_ctx->state = EMM_STATE_DEREGISTERED; @@ -509,7 +509,7 @@ bool s1ap::delete_ue_ctx(uint64_t imsi) return true; } -//UE Bearer Managment +// UE Bearer Managment void s1ap::activate_eps_bearer(uint64_t imsi, uint8_t ebi) { std::map::iterator ue_ctx_it = m_imsi_to_nas_ctx.find(imsi); @@ -530,10 +530,14 @@ void s1ap::activate_eps_bearer(uint64_t imsi, uint8_t ebi) if (esm_ctx->state != ERAB_CTX_SETUP) { m_s1ap_log->error( "Could not be activate EPS Bearer, bearer in wrong state: MME S1AP Id %d, EPS Bearer id %d, state %d\n", - mme_ue_s1ap_id, ebi, esm_ctx->state); + mme_ue_s1ap_id, + ebi, + esm_ctx->state); m_s1ap_log->console( "Could not be activate EPS Bearer, bearer in wrong state: MME S1AP Id %d, EPS Bearer id %d, state %d\n", - mme_ue_s1ap_id, ebi, esm_ctx->state); + mme_ue_s1ap_id, + ebi, + esm_ctx->state); return; } @@ -579,8 +583,8 @@ void s1ap::print_enb_ctx_info(const std::string& prefix, const enb_ctx_t& enb_ct srslte::mcc_to_string(enb_ctx.mcc, &mcc_str); srslte::mnc_to_string(enb_ctx.mnc, &mnc_str); m_s1ap_log->info("%s - MCC:%s, MNC:%s, PLMN: %d\n", prefix.c_str(), mcc_str.c_str(), mnc_str.c_str(), enb_ctx.plmn); - m_s1ap_log->console("%s - MCC:%s, MNC:%s, PLMN: %d\n", prefix.c_str(), mcc_str.c_str(), mnc_str.c_str(), - enb_ctx.plmn); + m_s1ap_log->console( + "%s - MCC:%s, MNC:%s, PLMN: %d\n", prefix.c_str(), mcc_str.c_str(), mnc_str.c_str(), enb_ctx.plmn); for (int i = 0; i < enb_ctx.nof_supported_ta; i++) { for (int j = 0; i < enb_ctx.nof_supported_ta; i++) { m_s1ap_log->info("%s - TAC %d, B-PLMN %d\n", prefix.c_str(), enb_ctx.tac[i], enb_ctx.bplmns[i][j]); diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 715a8e585..2be57714c 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -174,7 +174,8 @@ bool s1ap_ctx_mngmt_proc::send_initial_context_setup_request(nas* nas_ctx, uint1 m_s1ap_log->info("Sent Initial Context Setup Request. E-RAB id %d \n", erab_ctx_req->e_RAB_ID.E_RAB_ID); m_s1ap_log->info("Initial Context -- S1-U TEID 0x%x. IP %s \n", sgw_s1u_teid, inet_ntoa(addr)); m_s1ap_log->console("Initial Context Setup Request -- eNB UE S1AP Id %d, MME UE S1AP Id %d\n", - in_ctxt_req->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID, in_ctxt_req->MME_UE_S1AP_ID.MME_UE_S1AP_ID); + in_ctxt_req->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID, + in_ctxt_req->MME_UE_S1AP_ID.MME_UE_S1AP_ID); m_s1ap_log->console("Initial Context Setup Request -- E-RAB id %d\n", erab_ctx_req->e_RAB_ID.E_RAB_ID); m_s1ap_log->console("Initial Context Setup Request -- S1-U TEID 0x%x. IP %s \n", sgw_s1u_teid, inet_ntoa(addr)); m_s1ap_log->console("Initial Context Setup Request -- S1-U TEID 0x%x. IP %s \n", sgw_s1u_teid, inet_ntoa(addr)); @@ -224,8 +225,8 @@ bool s1ap_ctx_mngmt_proc::handle_initial_context_setup_response( m_s1ap_log->info("E-RAB Context Setup. E-RAB id %d\n", esm_ctx->erab_id); m_s1ap_log->info("E-RAB Context -- eNB TEID 0x%x, eNB Address %s\n", esm_ctx->enb_fteid.teid, enb_addr_str); m_s1ap_log->console("E-RAB Context Setup. E-RAB id %d\n", esm_ctx->erab_id); - m_s1ap_log->console("E-RAB Context -- eNB TEID 0x%x; eNB GTP-U Address %s\n", esm_ctx->enb_fteid.teid, - enb_addr_str); + m_s1ap_log->console( + "E-RAB Context -- eNB TEID 0x%x; eNB GTP-U Address %s\n", esm_ctx->enb_fteid.teid, enb_addr_str); } if (emm_ctx->state == EMM_STATE_REGISTERED) { diff --git a/srsepc/src/mme/s1ap_mngmt_proc.cc b/srsepc/src/mme/s1ap_mngmt_proc.cc index de986e911..ac7dc8ffa 100644 --- a/srsepc/src/mme/s1ap_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_mngmt_proc.cc @@ -79,8 +79,8 @@ bool s1ap_mngmt_proc::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST return false; } - //Store SCTP sendrecv info - memcpy(&enb_ctx.sri, enb_sri,sizeof(struct sctp_sndrcvinfo)); + // Store SCTP sendrecv info + memcpy(&enb_ctx.sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); // Log S1 Setup Request Info m_s1ap_log->console("Received S1 Setup Request.\n"); @@ -130,7 +130,8 @@ bool s1ap_mngmt_proc::unpack_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST } // eNB Id bzero(enb_id_bits, sizeof(enb_id_bits)); - memcpy(&enb_id_bits[32 - LIBLTE_S1AP_MACROENB_ID_BIT_STRING_LEN], msg->Global_ENB_ID.eNB_ID.choice.macroENB_ID.buffer, + memcpy(&enb_id_bits[32 - LIBLTE_S1AP_MACROENB_ID_BIT_STRING_LEN], + msg->Global_ENB_ID.eNB_ID.choice.macroENB_ID.buffer, LIBLTE_S1AP_MACROENB_ID_BIT_STRING_LEN); liblte_pack(enb_id_bits, 32, (uint8_t*)&tmp32); enb_ctx->enb_id = ntohl(tmp32); @@ -240,7 +241,7 @@ bool s1ap_mngmt_proc::pack_s1_setup_response(s1ap_args_t s1ap_args, srslte::byte s1_resp->RelativeMMECapacity.RelativeMMECapacity = 255; s1_resp->MMERelaySupportIndicator_present = false; - s1_resp->CriticalityDiagnostics_present = false; + s1_resp->CriticalityDiagnostics_present = false; liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)msg); return true; diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 6cd93791d..9a84ac24d 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -19,7 +19,6 @@ * */ -#include "srsepc/hdr/mme/mme.h" #include "srsepc/hdr/mme/s1ap_nas_transport.h" #include "srsepc/hdr/mme/mme.h" #include "srsepc/hdr/mme/s1ap.h" @@ -70,7 +69,7 @@ void s1ap_nas_transport::init() m_s1ap_log = m_s1ap->m_s1ap_log; m_pool = srslte::byte_buffer_pool::get_instance(); - //Init NAS args + // Init NAS args m_nas_init.mcc = m_s1ap->m_s1ap_args.mcc; m_nas_init.mnc = m_s1ap->m_s1ap_args.mnc; m_nas_init.mme_code = m_s1ap->m_s1ap_args.mme_code; @@ -121,8 +120,8 @@ bool s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUE case LIBLTE_MME_SECURITY_HDR_TYPE_SERVICE_REQUEST: m_s1ap_log->console("Received Initial UE message -- Service Request\n"); m_s1ap_log->info("Received Initial UE message -- Service Request\n"); - err = nas::handle_service_request(m_tmsi, enb_ue_s1ap_id, enb_sri, nas_msg, m_nas_init, m_nas_if, - m_s1ap->m_nas_log); + err = nas::handle_service_request( + m_tmsi, enb_ue_s1ap_id, enb_sri, nas_msg, m_nas_init, m_nas_if, m_s1ap->m_nas_log); break; case LIBLTE_MME_MSG_TYPE_DETACH_REQUEST: m_s1ap_log->console("Received Initial UE message -- Detach Request\n"); @@ -133,8 +132,8 @@ bool s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUE case LIBLTE_MME_MSG_TYPE_TRACKING_AREA_UPDATE_REQUEST: m_s1ap_log->console("Received Initial UE message -- Tracking Area Update Request\n"); m_s1ap_log->info("Received Initial UE message -- Tracking Area Update Request\n"); - err = nas::handle_tracking_area_update_request(m_tmsi, enb_ue_s1ap_id, enb_sri, nas_msg, m_nas_init, m_nas_if, - m_s1ap->m_nas_log); + err = nas::handle_tracking_area_update_request( + m_tmsi, enb_ue_s1ap_id, enb_sri, nas_msg, m_nas_init, m_nas_if, m_s1ap->m_nas_log); break; default: m_s1ap_log->info("Unhandled Initial UE Message 0x%x \n", msg_type); @@ -242,7 +241,8 @@ bool s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKN // - DETACH ACCEPT; // - TRACKING AREA UPDATE REQUEST. m_s1ap_log->info("UL NAS: sec_hdr_type: %s, mac_vaild: %s, msg_encrypted: %s\n", - liblte_nas_sec_hdr_type_to_string(sec_hdr_type), mac_valid == true ? "yes" : "no", + liblte_nas_sec_hdr_type_to_string(sec_hdr_type), + mac_valid == true ? "yes" : "no", msg_encrypted == true ? "yes" : "no"); switch (msg_type) { diff --git a/srsepc/src/spgw/gtpc.cc b/srsepc/src/spgw/gtpc.cc index d57f350bc..3b8309689 100644 --- a/srsepc/src/spgw/gtpc.cc +++ b/srsepc/src/spgw/gtpc.cc @@ -258,7 +258,8 @@ void spgw::gtpc::handle_modify_bearer_request(const struct srslte::gtpc_header& struct in_addr addr; addr.s_addr = tunnel_ctx->ue_ipv4; m_gtpc_log->info("IMSI: %015" PRIu64 ", UE IP: %s \n", tunnel_ctx->imsi, inet_ntoa(addr)); - m_gtpc_log->info("S-GW Rx Ctrl TEID 0x%x, MME Rx Ctrl TEID 0x%x\n", tunnel_ctx->up_ctrl_fteid.teid, + m_gtpc_log->info("S-GW Rx Ctrl TEID 0x%x, MME Rx Ctrl TEID 0x%x\n", + tunnel_ctx->up_ctrl_fteid.teid, tunnel_ctx->dw_ctrl_fteid.teid); m_gtpc_log->info("S-GW Rx Ctrl IP (NA), MME Rx Ctrl IP (NA)\n"); @@ -377,7 +378,8 @@ bool spgw::gtpc::send_downlink_data_notification(uint32_t spgw_ctr_teid) } void spgw::gtpc::handle_downlink_data_notification_acknowledge( - const srslte::gtpc_header& header, const srslte::gtpc_downlink_data_notification_acknowledge& not_ack) + const srslte::gtpc_header& header, + const srslte::gtpc_downlink_data_notification_acknowledge& not_ack) { m_gtpc_log->debug("Handling downlink data notification acknowledge\n"); @@ -405,7 +407,8 @@ void spgw::gtpc::handle_downlink_data_notification_acknowledge( } void spgw::gtpc::handle_downlink_data_notification_failure_indication( - const srslte::gtpc_header& header, const srslte::gtpc_downlink_data_notification_failure_indication& not_fail) + const srslte::gtpc_header& header, + const srslte::gtpc_downlink_data_notification_failure_indication& not_fail) { m_gtpc_log->debug("Handling downlink data notification failure indication\n"); // Find tunel ctxt @@ -508,11 +511,12 @@ bool spgw::gtpc::queue_downlink_packet(uint32_t ctrl_teid, srslte::byte_buffer_t if (tunnel_ctx->paging_queue.size() < m_max_paging_queue) { tunnel_ctx->paging_queue.push(msg); - m_gtpc_log->debug("Queued packet. IMSI %" PRIu64 ", Packets in Queue %zd\n", tunnel_ctx->imsi, - tunnel_ctx->paging_queue.size()); + m_gtpc_log->debug( + "Queued packet. IMSI %" PRIu64 ", Packets in Queue %zd\n", tunnel_ctx->imsi, tunnel_ctx->paging_queue.size()); } else { - m_gtpc_log->debug("Paging queue full. IMSI %" PRIu64 ", Packets in Queue %zd\n", tunnel_ctx->imsi, - tunnel_ctx->paging_queue.size()); + m_gtpc_log->debug("Paging queue full. IMSI %" PRIu64 ", Packets in Queue %zd\n", + tunnel_ctx->imsi, + tunnel_ctx->paging_queue.size()); goto pkt_discard; } return true; @@ -544,7 +548,8 @@ int spgw::gtpc::init_ue_ip(spgw_args_t* args, const std::maperror("SPGW: static ip addr %s for imsi %015" PRIu64 ", is reserved for the epc tun interface\n", - iter->first.c_str(), iter->second); + iter->first.c_str(), + iter->second); return SRSLTE_ERROR_OUT_OF_BOUNDS; } @@ -553,7 +558,8 @@ int spgw::gtpc::init_ue_ip(spgw_args_t* args, const std::mapfirst.c_str()); if (!m_imsi_to_ip.insert(std::make_pair(iter->second, in_addr)).second) { - m_gtpc_log->error("SPGW: duplicate imsi %015" PRIu64 " for static ip address %s.\n", iter->second, iter->first.c_str()); + m_gtpc_log->error( + "SPGW: duplicate imsi %015" PRIu64 " for static ip address %s.\n", iter->second, iter->first.c_str()); return SRSLTE_ERROR_OUT_OF_BOUNDS; } } @@ -567,7 +573,8 @@ int spgw::gtpc::init_ue_ip(spgw_args_t* args, const std::map::const_iterator iter = ip_to_imsi.find(inet_ntoa(ue_addr)); if (iter != ip_to_imsi.end()) { m_gtpc_log->debug("SPGW: init_ue_ip ue ip addr %s is reserved for imsi %015" PRIu64 ", not adding to pool\n", - iter->first.c_str(), iter->second); + iter->first.c_str(), + iter->second); } else { m_ue_ip_addr_pool.insert(ue_addr.s_addr); m_gtpc_log->debug("SPGW: init_ue_ip ue ip addr %s is added to pool\n", inet_ntoa(ue_addr)); diff --git a/srsepc/src/spgw/gtpu.cc b/srsepc/src/spgw/gtpu.cc index 1d9364669..3bb47591b 100644 --- a/srsepc/src/spgw/gtpu.cc +++ b/srsepc/src/spgw/gtpu.cc @@ -113,8 +113,8 @@ int spgw::gtpu::init_sgi(spgw_args_t* args) memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TUN | IFF_NO_PI; - strncpy(ifr.ifr_ifrn.ifrn_name, args->sgi_if_name.c_str(), - std::min(args->sgi_if_name.length(), (size_t)(IFNAMSIZ - 1))); + strncpy( + ifr.ifr_ifrn.ifrn_name, args->sgi_if_name.c_str(), std::min(args->sgi_if_name.length(), (size_t)(IFNAMSIZ - 1))); ifr.ifr_ifrn.ifrn_name[IFNAMSIZ - 1] = '\0'; if (ioctl(m_sgi, TUNSETIFF, &ifr) < 0) { @@ -146,8 +146,8 @@ int spgw::gtpu::init_sgi(spgw_args_t* args) addr->sin_port = 0; if (ioctl(sgi_sock, SIOCSIFADDR, &ifr) < 0) { - m_gtpu_log->error("Failed to set TUN interface IP. Address: %s, Error: %s\n", args->sgi_if_addr.c_str(), - strerror(errno)); + m_gtpu_log->error( + "Failed to set TUN interface IP. Address: %s, Error: %s\n", args->sgi_if_addr.c_str(), strerror(errno)); close(m_sgi); close(sgi_sock); return SRSLTE_ERROR_CANT_START; @@ -332,7 +332,8 @@ bool spgw::gtpu::modify_gtpu_tunnel(in_addr_t ue_ipv4, srslte::gtpc_f_teid_ie dw { m_gtpu_log->info("Modifying GTP-U Tunnel.\n"); m_gtpu_log->info("UE IP %s\n", srslte::gtpu_ntoa(ue_ipv4).c_str()); - m_gtpu_log->info("Downlink eNB addr %s, U-TEID 0x%x\n", srslte::gtpu_ntoa(dw_user_fteid.ipv4).c_str(), dw_user_fteid.teid); + m_gtpu_log->info( + "Downlink eNB addr %s, U-TEID 0x%x\n", srslte::gtpu_ntoa(dw_user_fteid.ipv4).c_str(), dw_user_fteid.teid); m_gtpu_log->info("Uplink C-TEID: 0x%x\n", up_ctrl_teid); m_ip_to_usr_teid[ue_ipv4] = dw_user_fteid; m_ip_to_ctr_teid[ue_ipv4] = up_ctrl_teid; diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index fb1dfff5b..d32dcedc5 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -117,8 +117,8 @@ void spgw::run_thread() struct sockaddr_in src_addr_in; struct sockaddr_un src_addr_un; - socklen_t addrlen; - struct iphdr* ip_pkt; + socklen_t addrlen; + struct iphdr* ip_pkt; int sgi = m_gtpu->get_sgi(); int s1u = m_gtpu->get_s1u(); @@ -153,7 +153,7 @@ void spgw::run_thread() * handle_downlink_data_notification_failure) */ m_spgw_log->debug("Message received at SPGW: SGi Message\n"); - sgi_msg = m_pool->allocate("spgw::run_thread::sgi_msg"); + sgi_msg = m_pool->allocate("spgw::run_thread::sgi_msg"); sgi_msg->N_bytes = read(sgi, sgi_msg->msg, buf_len); m_gtpu->handle_sgi_pdu(sgi_msg); }