From 724bc6cbb540d5052a0e2142b586d017fad35df1 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 23 Jan 2018 15:26:54 +0000 Subject: [PATCH 001/143] rm boost::mutex from S1AP. --- srsepc/src/mme/s1ap.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 07563e7ca..ef6a116f4 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -34,7 +34,7 @@ namespace srsepc{ s1ap* s1ap::m_instance = NULL; -boost::mutex s1ap_instance_mutex; +pthread_mutex_t s1ap_instance_mutex = PTHREAD_MUTEX_INITIALIZER; s1ap::s1ap(): m_s1mme(-1), @@ -49,21 +49,24 @@ s1ap::~s1ap() s1ap* s1ap::get_instance(void) { - boost::mutex::scoped_lock lock(s1ap_instance_mutex); - if(NULL == m_instance) { + + pthread_mutex_lock(&s1ap_instance_mutex); + if(m_instance == NULL) { m_instance = new s1ap(); } + pthread_mutex_unlock(&s1ap_instance_mutex); return(m_instance); } void s1ap::cleanup(void) { - boost::mutex::scoped_lock lock(s1ap_instance_mutex); + pthread_mutex_lock(&s1ap_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&s1ap_instance_mutex); } int From 99e1a9f0382353658aa4e775f69b6510b28731cc Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 24 Jan 2018 10:31:47 +0000 Subject: [PATCH 002/143] rm boost::mutex from MME --- srsepc/src/mme/mme.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/srsepc/src/mme/mme.cc b/srsepc/src/mme/mme.cc index ab4778c20..56766fa6b 100644 --- a/srsepc/src/mme/mme.cc +++ b/srsepc/src/mme/mme.cc @@ -29,13 +29,12 @@ #include #include #include -#include #include "mme/mme.h" namespace srsepc{ mme* mme::m_instance = NULL; -boost::mutex mme_instance_mutex; +pthread_mutex_t mme_instance_mutex = PTHREAD_MUTEX_INITIALIZER; mme::mme(): m_running(false) @@ -52,21 +51,23 @@ mme::~mme() mme* mme::get_instance(void) { - boost::mutex::scoped_lock lock(mme_instance_mutex); + pthread_mutex_lock(&mme_instance_mutex); if(NULL == m_instance) { m_instance = new mme(); } + pthread_mutex_unlock(&mme_instance_mutex); return(m_instance); } void mme::cleanup(void) { - boost::mutex::scoped_lock lock(mme_instance_mutex); + pthread_mutex_lock(&mme_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&mme_instance_mutex); } int From d87023bb37bd785b96c67bdf20dc76d622f834fb Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 24 Jan 2018 11:17:34 +0000 Subject: [PATCH 003/143] rm boost::mutex from s1ap_nas_transport --- srsepc/src/mme/s1ap_nas_transport.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index e5bf2890a..0054041fe 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -31,7 +31,7 @@ namespace srsepc{ s1ap_nas_transport* s1ap_nas_transport::m_instance = NULL; -boost::mutex s1ap_nas_transport_instance_mutex; +pthread_mutex_t s1ap_nas_transport_instance_mutex = PTHREAD_MUTEX_INITIALIZER; s1ap_nas_transport::s1ap_nas_transport() { @@ -46,21 +46,23 @@ s1ap_nas_transport::~s1ap_nas_transport() s1ap_nas_transport* s1ap_nas_transport::get_instance(void) { - boost::mutex::scoped_lock lock(s1ap_nas_transport_instance_mutex); + pthread_mutex_lock(&s1ap_nas_transport_instance_mutex); if(NULL == m_instance) { m_instance = new s1ap_nas_transport(); } + pthread_mutex_unlock(&s1ap_nas_transport_instance_mutex); return(m_instance); } void s1ap_nas_transport::cleanup(void) { - boost::mutex::scoped_lock lock(s1ap_nas_transport_instance_mutex); + pthread_mutex_lock(&s1ap_nas_transport_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&s1ap_nas_transport_instance_mutex); } void From 360bb5e2d60552bdfe08f0239eb40e9a617b30ca Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 24 Jan 2018 13:50:03 +0000 Subject: [PATCH 004/143] rm boost::mutex from s1ap_mngmnt_proc --- srsepc/src/mme/s1ap_mngmt_proc.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/srsepc/src/mme/s1ap_mngmt_proc.cc b/srsepc/src/mme/s1ap_mngmt_proc.cc index 8fa469ec3..477ce203f 100644 --- a/srsepc/src/mme/s1ap_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_mngmt_proc.cc @@ -32,7 +32,7 @@ namespace srsepc{ s1ap_mngmt_proc* s1ap_mngmt_proc::m_instance = NULL; -boost::mutex s1ap_mngmt_proc_instance_mutex; +pthread_mutex_t s1ap_mngmt_proc_instance_mutex = PTHREAD_MUTEX_INITIALIZER; s1ap_mngmt_proc::s1ap_mngmt_proc() @@ -46,21 +46,23 @@ s1ap_mngmt_proc::~s1ap_mngmt_proc() s1ap_mngmt_proc* s1ap_mngmt_proc::get_instance(void) { - boost::mutex::scoped_lock lock(s1ap_mngmt_proc_instance_mutex); + pthread_mutex_lock(&s1ap_mngmt_proc_instance_mutex); if(NULL == m_instance) { m_instance = new s1ap_mngmt_proc(); } return(m_instance); + pthread_mutex_unlock(&s1ap_mngmt_proc_instance_mutex); } void s1ap_mngmt_proc::cleanup(void) { - boost::mutex::scoped_lock lock(s1ap_mngmt_proc_instance_mutex); + pthread_mutex_lock(&s1ap_mngmt_proc_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&s1ap_mngmt_proc_instance_mutex); } void From aa437806d8218b03d4032487e61304afac327bad Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 24 Jan 2018 15:47:06 +0000 Subject: [PATCH 005/143] rm boost::mutex from s1ap_ctx_mngmt --- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 7dffe3c35..2be599c87 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -34,7 +34,7 @@ namespace srsepc{ s1ap_ctx_mngmt_proc* s1ap_ctx_mngmt_proc::m_instance = NULL; -boost::mutex s1ap_ctx_mngmt_proc_instance_mutex; +pthread_mutex_t s1ap_ctx_mngmt_proc_instance_mutex = PTHREAD_MUTEX_INITIALIZER; s1ap_ctx_mngmt_proc::s1ap_ctx_mngmt_proc() @@ -48,21 +48,23 @@ s1ap_ctx_mngmt_proc::~s1ap_ctx_mngmt_proc() s1ap_ctx_mngmt_proc* s1ap_ctx_mngmt_proc::get_instance(void) { - boost::mutex::scoped_lock lock(s1ap_ctx_mngmt_proc_instance_mutex); + pthread_mutex_lock(&s1ap_ctx_mngmt_proc_instance_mutex); if(NULL == m_instance) { m_instance = new s1ap_ctx_mngmt_proc(); } + pthread_mutex_unlock(&s1ap_ctx_mngmt_proc_instance_mutex); return(m_instance); } void s1ap_ctx_mngmt_proc::cleanup(void) { - boost::mutex::scoped_lock lock(s1ap_ctx_mngmt_proc_instance_mutex); + pthread_mutex_lock(&s1ap_ctx_mngmt_proc_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&s1ap_ctx_mngmt_proc_instance_mutex); } void From 628ccec07f3a2eeb2473c6b24509136f0288e9b9 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 24 Jan 2018 16:41:59 +0000 Subject: [PATCH 006/143] Removed boost::mutex from EPC --- srsepc/src/hss/hss.cc | 10 ++++++---- srsepc/src/mme/s1ap_mngmt_proc.cc | 2 +- srsepc/src/spgw/spgw.cc | 8 +++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/srsepc/src/hss/hss.cc b/srsepc/src/hss/hss.cc index 5fc383078..36b47d0e3 100644 --- a/srsepc/src/hss/hss.cc +++ b/srsepc/src/hss/hss.cc @@ -36,7 +36,7 @@ using namespace srslte; namespace srsepc{ hss* hss::m_instance = NULL; -boost::mutex hss_instance_mutex; +pthread_mutex_t hss_instance_mutex = PTHREAD_MUTEX_INITIALIZER; hss::hss() // :m_sqn(0x112233445566) @@ -53,22 +53,24 @@ hss::~hss() hss* hss::get_instance(void) -{ - boost::mutex::scoped_lock lock(hss_instance_mutex); +{ + pthread_mutex_lock(&hss_instance_mutex); if(NULL == m_instance) { m_instance = new hss(); } + pthread_mutex_unlock(&hss_instance_mutex); return(m_instance); } void hss::cleanup(void) { - boost::mutex::scoped_lock lock(hss_instance_mutex); + pthread_mutex_lock(&hss_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&hss_instance_mutex); } int diff --git a/srsepc/src/mme/s1ap_mngmt_proc.cc b/srsepc/src/mme/s1ap_mngmt_proc.cc index 477ce203f..3aa3688e0 100644 --- a/srsepc/src/mme/s1ap_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_mngmt_proc.cc @@ -50,8 +50,8 @@ s1ap_mngmt_proc::get_instance(void) if(NULL == m_instance) { m_instance = new s1ap_mngmt_proc(); } - return(m_instance); pthread_mutex_unlock(&s1ap_mngmt_proc_instance_mutex); + return(m_instance); } void diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index 2458a065b..2f0e0e468 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -41,7 +41,7 @@ namespace srsepc{ spgw* spgw::m_instance = NULL; -boost::mutex spgw_instance_mutex; +pthread_mutex_t spgw_instance_mutex = PTHREAD_MUTEX_INITIALIZER; const uint16_t SPGW_BUFFER_SIZE = 2500; @@ -63,21 +63,23 @@ spgw::~spgw() spgw* spgw::get_instance(void) { - boost::mutex::scoped_lock lock(spgw_instance_mutex); + pthread_mutex_lock(&spgw_instance_mutex); if(NULL == m_instance) { m_instance = new spgw(); } + pthread_mutex_unlock(&spgw_instance_mutex); return(m_instance); } void spgw::cleanup(void) { - boost::mutex::scoped_lock lock(spgw_instance_mutex); + pthread_mutex_lock(&spgw_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&spgw_instance_mutex); } int From af2816f83fa52052f3eb93d0a7c37d384974519b Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 26 Jan 2018 17:43:21 +0000 Subject: [PATCH 007/143] Staring to make APN configurable. --- srsepc/epc.conf.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/srsepc/epc.conf.example b/srsepc/epc.conf.example index 739b2c137..2576d127a 100644 --- a/srsepc/epc.conf.example +++ b/srsepc/epc.conf.example @@ -10,7 +10,7 @@ # tac: 16-bit Tracking Area Code. # mcc: Mobile Country Code # mnc: Mobile Network Code -# mme_bindx_addr: IP subnet to listen for eNB S1 connnections +# mme_bind_addr: IP bind addr to listen for eNB S1 connnections # ##################################################################### [mme] @@ -20,6 +20,7 @@ tac = 0x0007 mcc = 001 mnc = 01 mme_bind_addr = 127.0.1.100 +apn = srsapn ##################################################################### # HSS configuration From 7013865c0d5695b4586f802d8061a1403b26c7d2 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 30 Jan 2018 14:41:23 +0000 Subject: [PATCH 008/143] fixed un-initialized values in attach accept. --- srsepc/src/mme/s1ap_nas_transport.cc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 0054041fe..52e8e6775 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -117,13 +117,15 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA } handle_nas_attach_request(enb_ue_s1ap_id, attach_req,pdn_con_req,reply_buffer,reply_flag, enb_sri); } + /* else if(msg_type == LIBLTE_MME_SECURITY_HDR_TYPE_SERVICE_REQUEST) { m_s1ap_log->info("Received Service Request \n"); m_s1ap_log->console("Received Service Request \n"); - liblte_mme_unpack_service_request_msg((LIBLTE_BYTE_MSG_STRUCT*) nas_msg, &service_req); + liblte_mme_unpack_service_request_msg((LIBLTE_BYTE_MSG_STRUCT*) nas_msg, &service_req); + handle_nas_service_request(enb_ue_s1ap_id, attach_req,pdn_con_req,reply_buffer,reply_flag, enb_sri); return false; - } + }*/ m_pool->deallocate(nas_msg); return true; @@ -422,6 +424,18 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, return true; } + /* +bool +s1ap_nas_transport::handle_nas_service_request(uint32_t enb_ue_s1ap_id, + const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, + const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri) +{ + +}*/ + bool s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag) { @@ -1093,6 +1107,14 @@ s1ap_nas_transport::pack_attach_accept(ue_ctx_t *ue_ctx, LIBLTE_S1AP_E_RABTOBESE act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents[2] = 8; act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents[3] = 8; + //Make sure all unused options are set to false + act_def_eps_bearer_context_req.negotiated_qos_present = false; + act_def_eps_bearer_context_req.llc_sapi_present = false; + act_def_eps_bearer_context_req.radio_prio_present = false; + act_def_eps_bearer_context_req.packet_flow_id_present = false; + act_def_eps_bearer_context_req.apn_ambr_present = false; + act_def_eps_bearer_context_req.esm_cause_present = false; + uint8_t sec_hdr_type =2; ue_ctx->security_ctxt.dl_nas_count++; liblte_mme_pack_activate_default_eps_bearer_context_request_msg(&act_def_eps_bearer_context_req, &attach_accept.esm_msg); From c4b2dd5e65ca48f132b4761cf421eea5e8f18033 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 2 Feb 2018 19:08:51 +0000 Subject: [PATCH 009/143] Starting to add the response to the service request. --- srsepc/hdr/mme/s1ap_nas_transport.h | 8 +++ srsepc/src/mme/s1ap.cc | 6 ++- srsepc/src/mme/s1ap_nas_transport.cc | 75 ++++++++++++++++++++++++++-- 3 files changed, 82 insertions(+), 7 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index e37ce4d61..bb8f7967f 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -47,6 +47,7 @@ public: bool handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *init_ue, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRANSPORT_STRUCT *ul_xport, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); + //Initial UE messages bool handle_nas_attach_request( uint32_t enb_ue_s1ap_id, const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, @@ -65,6 +66,13 @@ public: srslte::byte_buffer_t *reply_buffer, bool* reply_flag, struct sctp_sndrcvinfo *enb_sri); + bool handle_nas_service_request(uint32_t enb_ue_s1ap_id, + const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, + const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri); + bool handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag); bool handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 85a07596c..e0604b113 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -259,7 +259,7 @@ s1ap::handle_s1ap_rx_pdu(srslte::byte_buffer_t *pdu, struct sctp_sndrcvinfo *enb } -bool +bool s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri) { bool reply_flag = false; @@ -291,7 +291,9 @@ s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, stru ssize_t n_sent = sctp_send(m_s1mme,reply_buffer->msg, reply_buffer->N_bytes, enb_sri, 0); if(n_sent == -1) { - m_s1ap_log->console("Failed to send S1 Setup Setup Reply\n"); + m_s1ap_log->console("Failed to send S1AP Initiating Reply.\n"); + m_s1ap_log->error("Failed to send S1AP Initiating Reply. \n"); + m_pool->deallocate(reply_buffer); m_pool->deallocate(reply_buffer); return false; } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index c6f86db56..3f2a1eb49 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -117,7 +117,6 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA } handle_nas_attach_request(enb_ue_s1ap_id, attach_req,pdn_con_req,reply_buffer,reply_flag, enb_sri); } - /* else if(msg_type == LIBLTE_MME_SECURITY_HDR_TYPE_SERVICE_REQUEST) { m_s1ap_log->info("Received Service Request \n"); @@ -125,7 +124,7 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA liblte_mme_unpack_service_request_msg((LIBLTE_BYTE_MSG_STRUCT*) nas_msg, &service_req); handle_nas_service_request(enb_ue_s1ap_id, attach_req,pdn_con_req,reply_buffer,reply_flag, enb_sri); return false; - }*/ + } m_pool->deallocate(nas_msg); return true; @@ -424,7 +423,6 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, return true; } - /* bool s1ap_nas_transport::handle_nas_service_request(uint32_t enb_ue_s1ap_id, const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, @@ -433,8 +431,70 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t enb_ue_s1ap_id, bool* reply_flag, struct sctp_sndrcvinfo *enb_sri) { + m_s1ap_log->warning("Service Request not handled yet\n"); + m_s1ap_log->console("Service Request not handled yet\n"); + + srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); + + //Setup initiating message + LIBLTE_S1AP_S1AP_PDU_STRUCT tx_pdu; + bzero(&tx_pdu, sizeof(LIBLTE_S1AP_S1AP_PDU_STRUCT)); + + tx_pdu.ext = false; + tx_pdu.choice_type = LIBLTE_S1AP_S1AP_PDU_CHOICE_INITIATINGMESSAGE; + + LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *init = &tx_pdu.choice.initiatingMessage; + init->procedureCode = LIBLTE_S1AP_PROC_ID_DOWNLINKNASTRANSPORT; + init->choice_type = LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_DOWNLINKNASTRANSPORT; + + //Setup Dw NAS structure + LIBLTE_S1AP_MESSAGE_DOWNLINKNASTRANSPORT_STRUCT *dw_nas = &init->choice.DownlinkNASTransport; + dw_nas->ext=false; + dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = 16; + dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = enb_ue_s1ap_id; + dw_nas->HandoverRestrictionList_present=false; + dw_nas->SubscriberProfileIDforRFP_present=false; -}*/ + LIBLTE_MME_SERVICE_REJECT_MSG_STRUCT serv_rej; + serv_rej.t3442_present = false; + serv_rej.t3446_present = false; + serv_rej.emm_cause = 9; //UE Identity cannot be derived by the network + + uint8_t sec_hdr_type = 2; + uint32_t count = 0 ; + LIBLTE_ERROR_ENUM err; + err = liblte_mme_pack_service_reject_msg(&serv_rej, sec_hdr_type, count, (LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); + if(err != LIBLTE_SUCCESS) + { + m_s1ap_log->error("Error packing Athentication Reject\n"); + m_s1ap_log->console("Error packing Athentication Reject\n"); + return false; + } + + //Copy NAS PDU to Downlink NAS Trasport message buffer + memcpy(dw_nas->NAS_PDU.buffer, nas_buffer->msg, nas_buffer->N_bytes); + dw_nas->NAS_PDU.n_octets = nas_buffer->N_bytes; + + //Pack Downlink NAS Transport Message + err = liblte_s1ap_pack_s1ap_pdu(&tx_pdu, (LIBLTE_BYTE_MSG_STRUCT *) reply_buffer); + if(err != LIBLTE_SUCCESS) + { + m_s1ap_log->error("Error packing Athentication Request\n"); + m_s1ap_log->console("Error packing Athentication Request\n"); + return false; + } + + + + bool send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, struct srslte::gtpc_create_session_response *cs_resp, struct srslte::gtpc_f_teid_ie sgw_ctrl_fteid); + m_pool->deallocate(nas_buffer); + + //Send reply to eNB + *reply_flag = true; + m_s1ap_log->info("Downlink NAS: Sending Athentication Request\n"); + m_s1ap_log->console("Downlink NAS: Sending Athentication Request\n"); + return true; +} bool s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag) @@ -1063,11 +1123,16 @@ s1ap_nas_transport::pack_attach_accept(ue_ctx_t *ue_ctx, LIBLTE_S1AP_E_RABTOBESE attach_accept.guti.guti.mme_code, attach_accept.guti.guti.m_tmsi); + + attach_accept.t3402_present=true; + attach_accept.t3402.unit = LIBLTE_MME_GPRS_TIMER_UNIT_1_MINUTE; // GPRS 1 minute unit + attach_accept.t3402.value = 30; // 30 minute periodic timer + //Make sure all unused options are set to false attach_accept.lai_present=false; attach_accept.ms_id_present=false; attach_accept.emm_cause_present=false; - attach_accept.t3402_present=false; + //attach_accept.t3402_present=false; attach_accept.t3423_present=false; attach_accept.equivalent_plmns_present=false; attach_accept.emerg_num_list_present=false; From 955be59a594985a10af2f77ccba69ac313ed1042 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Sat, 3 Feb 2018 11:06:03 +0000 Subject: [PATCH 010/143] starting to add EMM states to keep EMM state, security context, etc., even when UE context release request is received. --- srsepc/hdr/mme/s1ap_common.h | 48 +++++++++++++++++++++++++-- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 4 +-- srsepc/src/mme/s1ap_nas_transport.cc | 28 ++++++++-------- 3 files changed, 61 insertions(+), 19 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index f5462ad65..2d693eba9 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -33,6 +33,47 @@ 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_ERABS_PER_UE = 16; +// MME EMM states (3GPP 24.301 v10.0.0, section 5.1.3.4) +typedef enum { + EMM_STATE_DEREGISTERED = 0, + EMM_STATE_COMMON_PROCEDURE_INITIATED, + EMM_STATE_REGISTERED, + 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", + "DEREGISTERED INITIATED"}; + +// MME ECM states (3GPP 23.401 v10.0.0, section 4.6.3) +typedef enum { + ECM_STATE_IDLE = 0, + ECM_STATE_CONNECTED, + ECM_STATE_N_ITEMS, +} ecm_state_t; +static const char ecm_state_text[ECM_STATE_N_ITEMS][100] = {"IDLE", + "CONNECTED"}; + +// MME ESM states (3GPP 23.401 v10.0.0, section 4.6.3) +typedef enum { + ESM_BEARER_CONTEXT_INACTIVE = 0, + ESM_BEARER_CONTEXT_ACTIVE_PENDING, + ESM_BEARER_CONTEXT_ACTIVE, + ESM_BEARER_CONTEXT_INACTIVE_PENDING, + ESM_BEARER_CONTEXT_MODIFY_PENDING, + ESM_BEARER_PROCEDURE_TRANSACTION_INACTIVE, + ESM_BEARER_PROCEDURE_TRANSACTION_PENDING, + ESM_STATE_N_ITEMS, +} esm_state_t; +static const char esm_state_text[ESM_STATE_N_ITEMS][100] = {"CONTEXT INACTIVE", + "CONTEXT ACTIVE PENDING", + "CONTEXT ACTIVE", + "CONTEXT_INACTIVE_PENDING", + "CONTEXT_MODIFY_PENDING", + "PROCEDURE_TRANSACTION_INACTIVE" + "PROCEDURE_TRANSACTION_PENDING"}; + enum erab_state { ERAB_DEACTIVATED, @@ -74,6 +115,9 @@ typedef struct{ srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo; uint8_t k_nas_enc[32]; uint8_t k_nas_int[32]; + LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT ue_network_cap; + bool ms_network_cap_present; + LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT ms_network_cap; } eps_security_ctx_t; typedef struct{ @@ -89,11 +133,9 @@ typedef struct{ uint32_t mme_ue_s1ap_id; uint16_t enb_id; struct sctp_sndrcvinfo enb_sri; + emm_state_t emm_state; eps_security_ctx_t security_ctxt; erab_ctx_t erabs_ctx[MAX_ERABS_PER_UE]; - LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT ue_network_cap; - bool ms_network_cap_present; - LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT ms_network_cap; bool eit; uint8_t procedure_transaction_id; } ue_ctx_t; diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 7dffe3c35..1d6df8cf3 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -143,7 +143,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, bzero(in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer,sizeof(uint8_t)*16); for(int i = 0; i<3; i++) { - if(ue_ctx->ue_network_cap.eea[i+1] == true) + if(ue_ctx->security_ctxt.ue_network_cap.eea[i+1] == true) { in_ctxt_req->UESecurityCapabilities.encryptionAlgorithms.buffer[i] = 1; //EEA supported } @@ -151,7 +151,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, { in_ctxt_req->UESecurityCapabilities.encryptionAlgorithms.buffer[i] = 0; //EEA not supported } - if(ue_ctx->ue_network_cap.eia[i+1] == true) + if(ue_ctx->security_ctxt.ue_network_cap.eia[i+1] == true) { in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer[i] = 1; //EEA supported } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 7ba6fbe25..a200369a7 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -250,11 +250,11 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, ue_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); //Save UE network capabilities - memcpy(&ue_ctx.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); - ue_ctx.ms_network_cap_present = attach_req.ms_network_cap_present; + memcpy(&ue_ctx.security_ctxt.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); + ue_ctx.security_ctxt.ms_network_cap_present = attach_req.ms_network_cap_present; if(attach_req.ms_network_cap_present) { - memcpy(&ue_ctx.ms_network_cap, &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); + memcpy(&ue_ctx.security_ctxt.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 ue_ctx.procedure_transaction_id = pdn_con_req.proc_transaction_id; @@ -345,11 +345,11 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, ue_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); //Save UE network capabilities - memcpy(&ue_ctx.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); - ue_ctx.ms_network_cap_present = attach_req.ms_network_cap_present; + memcpy(&ue_ctx.security_ctxt.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); + ue_ctx.security_ctxt.ms_network_cap_present = attach_req.ms_network_cap_present; if(attach_req.ms_network_cap_present) { - memcpy(&ue_ctx.ms_network_cap, &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); + memcpy(&ue_ctx.security_ctxt.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 ue_ctx.procedure_transaction_id = pdn_con_req.proc_transaction_id; @@ -863,14 +863,14 @@ s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, sm_cmd.nas_ksi.nas_ksi=0; //Replay UE security cap - memcpy(sm_cmd.ue_security_cap.eea,ue_ctx->ue_network_cap.eea,8*sizeof(bool)); - memcpy(sm_cmd.ue_security_cap.eia,ue_ctx->ue_network_cap.eia,8*sizeof(bool)); - sm_cmd.ue_security_cap.uea_present = ue_ctx->ue_network_cap.uea_present; - memcpy(sm_cmd.ue_security_cap.uea,ue_ctx->ue_network_cap.uea,8*sizeof(bool)); - sm_cmd.ue_security_cap.uia_present = ue_ctx->ue_network_cap.uia_present; - memcpy(sm_cmd.ue_security_cap.uia,ue_ctx->ue_network_cap.uia,8*sizeof(bool)); - sm_cmd.ue_security_cap.gea_present = ue_ctx->ms_network_cap_present; - memcpy(sm_cmd.ue_security_cap.gea,ue_ctx->ms_network_cap.gea,8*sizeof(bool)); + memcpy(sm_cmd.ue_security_cap.eea,ue_ctx->security_ctxt.ue_network_cap.eea,8*sizeof(bool)); + memcpy(sm_cmd.ue_security_cap.eia,ue_ctx->security_ctxt.ue_network_cap.eia,8*sizeof(bool)); + sm_cmd.ue_security_cap.uea_present = ue_ctx->security_ctxt.ue_network_cap.uea_present; + memcpy(sm_cmd.ue_security_cap.uea,ue_ctx->security_ctxt.ue_network_cap.uea,8*sizeof(bool)); + sm_cmd.ue_security_cap.uia_present = ue_ctx->security_ctxt.ue_network_cap.uia_present; + memcpy(sm_cmd.ue_security_cap.uia,ue_ctx->security_ctxt.ue_network_cap.uia,8*sizeof(bool)); + sm_cmd.ue_security_cap.gea_present = ue_ctx->security_ctxt.ms_network_cap_present; + memcpy(sm_cmd.ue_security_cap.gea,ue_ctx->security_ctxt.ms_network_cap.gea,8*sizeof(bool)); sm_cmd.imeisv_req_present=false; sm_cmd.nonce_ue_present=false; From 0beb54e6969a88a7d99b7d07b48cb68268c88613 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Sat, 3 Feb 2018 17:36:57 +0000 Subject: [PATCH 011/143] Re-organized some functions. --- srsepc/src/mme/s1ap.cc | 142 ++++++++++++++++++++++------------------- 1 file changed, 75 insertions(+), 67 deletions(-) diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index a3c68bc26..03e812bba 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -88,10 +88,8 @@ s1ap::init(s1ap_args_t s1ap_args, srslte::log_filter *s1ap_log) //Get pointer to the HSS m_hss = hss::get_instance(); - //Get pointer to GTP-C class m_mme_gtpc = mme_gtpc::get_instance(); - //Initialize S1-MME m_s1mme = enb_listen(); @@ -122,49 +120,9 @@ s1ap::stop() return; } -void -s1ap::delete_enb_ctx(int32_t assoc_id) -{ - std::map::iterator it_assoc = m_sctp_to_enb_id.find(assoc_id); - uint16_t enb_id = it_assoc->second; - - std::map::iterator it_ctx = m_active_enbs.find(enb_id); - if(it_ctx == m_active_enbs.end() || it_assoc == m_sctp_to_enb_id.end()) - { - m_s1ap_log->error("Could not find eNB to delete. Association: %d\n",assoc_id); - return; - } - m_s1ap_log->info("Deleting eNB context. eNB Id: 0x%x\n", enb_id); - m_s1ap_log->console("Deleting eNB context. eNB Id: 0x%x\n", enb_id); - //Delete connected UEs ctx - delete_ues_in_enb(enb_id); - - //Delete eNB - delete it_ctx->second; - m_active_enbs.erase(it_ctx); - m_sctp_to_enb_id.erase(it_assoc); - return; -} - -void -s1ap::delete_ues_in_enb(uint16_t enb_id) -{ - //delete UEs ctx - std::map >::iterator ues_in_enb = m_enb_id_to_ue_ids.find(enb_id); - std::set::iterator ue_id = ues_in_enb->second.begin(); - while(ue_id != ues_in_enb->second.end() ) - { - std::map::iterator ue_ctx = m_active_ues.find(*ue_id); - m_s1ap_log->info("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); - m_s1ap_log->console("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); - delete ue_ctx->second; //delete UE context - m_active_ues.erase(ue_ctx); //remove from general MME map - ues_in_enb->second.erase(ue_id++); //erase from the eNB's UE set - } -} int s1ap::get_s1_mme() @@ -310,6 +268,80 @@ s1ap::handle_successful_outcome(LIBLTE_S1AP_SUCCESSFULOUTCOME_STRUCT *msg) return true; } +//eNB Context Managment +void +s1ap::add_new_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo *enb_sri) +{ + m_s1ap_log->info("Adding new eNB context. eNB ID %d\n", enb_ctx.enb_id); + std::set ue_set; + enb_ctx_t *enb_ptr = new enb_ctx_t; + memcpy(enb_ptr,&enb_ctx,sizeof(enb_ctx_t)); + m_active_enbs.insert(std::pair(enb_ptr->enb_id,enb_ptr)); + m_sctp_to_enb_id.insert(std::pair(enb_sri->sinfo_assoc_id, enb_ptr->enb_id)); + m_enb_id_to_ue_ids.insert(std::pair >(enb_ptr->enb_id,ue_set)); + + return; +} + +enb_ctx_t* +s1ap::find_enb_ctx(uint16_t enb_id) +{ + std::map::iterator it = m_active_enbs.find(enb_id); + if(it == m_active_enbs.end()) + { + return NULL; + } + else + { + return it->second; + } +} + +void +s1ap::delete_enb_ctx(int32_t assoc_id) +{ + std::map::iterator it_assoc = m_sctp_to_enb_id.find(assoc_id); + uint16_t enb_id = it_assoc->second; + + std::map::iterator it_ctx = m_active_enbs.find(enb_id); + if(it_ctx == m_active_enbs.end() || it_assoc == m_sctp_to_enb_id.end()) + { + m_s1ap_log->error("Could not find eNB to delete. Association: %d\n",assoc_id); + return; + } + + m_s1ap_log->info("Deleting eNB context. eNB Id: 0x%x\n", enb_id); + m_s1ap_log->console("Deleting eNB context. eNB Id: 0x%x\n", enb_id); + + //Delete connected UEs ctx + delete_ues_in_enb(enb_id); + + //Delete eNB + delete it_ctx->second; + m_active_enbs.erase(it_ctx); + m_sctp_to_enb_id.erase(it_assoc); + return; +} + + +//UE Context Management +void +s1ap::delete_ues_in_enb(uint16_t enb_id) +{ + //delete UEs ctx + std::map >::iterator ues_in_enb = m_enb_id_to_ue_ids.find(enb_id); + std::set::iterator ue_id = ues_in_enb->second.begin(); + while(ue_id != ues_in_enb->second.end() ) + { + std::map::iterator ue_ctx = m_active_ues.find(*ue_id); + m_s1ap_log->info("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); + m_s1ap_log->console("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); + delete ue_ctx->second; //delete UE context + m_active_ues.erase(ue_ctx); //remove from general MME map + ues_in_enb->second.erase(ue_id++); //erase from the eNB's UE set + } + +} bool s1ap::delete_ue_ctx(ue_ctx_t *ue_ctx) @@ -346,33 +378,9 @@ s1ap::delete_ue_ctx(ue_ctx_t *ue_ctx) return true; } -enb_ctx_t* -s1ap::find_enb_ctx(uint16_t enb_id) -{ - std::map::iterator it = m_active_enbs.find(enb_id); - if(it == m_active_enbs.end()) - { - return NULL; - } - else - { - return it->second; - } -} -void -s1ap::add_new_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo *enb_sri) -{ - m_s1ap_log->info("Adding new eNB context. eNB ID %d\n", enb_ctx.enb_id); - std::set ue_set; - enb_ctx_t *enb_ptr = new enb_ctx_t; - memcpy(enb_ptr,&enb_ctx,sizeof(enb_ctx_t)); - m_active_enbs.insert(std::pair(enb_ptr->enb_id,enb_ptr)); - m_sctp_to_enb_id.insert(std::pair(enb_sri->sinfo_assoc_id, enb_ptr->enb_id)); - m_enb_id_to_ue_ids.insert(std::pair >(enb_ptr->enb_id,ue_set)); - return; -} + ue_ctx_t* s1ap::find_ue_ctx(uint32_t mme_ue_s1ap_id) From cc9e1294c635d70cc9f60c7d7805af9b556b96b1 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 5 Feb 2018 10:46:57 +0000 Subject: [PATCH 012/143] re-organized some functions. --- srsepc/src/mme/s1ap.cc | 64 ++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 03e812bba..d91b4c4c5 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -325,6 +325,39 @@ s1ap::delete_enb_ctx(int32_t assoc_id) //UE Context Management +void +s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) +{ + ue_ctx_t *ue_ptr = new ue_ctx_t; + memcpy(ue_ptr,&ue_ctx,sizeof(ue_ctx)); + m_active_ues.insert(std::pair(ue_ptr->mme_ue_s1ap_id,ue_ptr)); + + std::map::iterator it_enb = m_sctp_to_enb_id.find(ue_ptr->enb_sri.sinfo_assoc_id); + uint16_t enb_id = it_enb->second; + std::map >::iterator it_ue_id = m_enb_id_to_ue_ids.find(enb_id); + if(it_ue_id==m_enb_id_to_ue_ids.end()) + { + m_s1ap_log->error("Could not find eNB's UEs\n"); + return; + } + it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); + return; +} + +ue_ctx_t* +s1ap::find_ue_ctx(uint32_t mme_ue_s1ap_id) +{ + std::map::iterator it = m_active_ues.find(mme_ue_s1ap_id); + if(it == m_active_ues.end()) + { + return NULL; + } + else + { + return it->second; + } +} + void s1ap::delete_ues_in_enb(uint16_t enb_id) { @@ -382,38 +415,7 @@ s1ap::delete_ue_ctx(ue_ctx_t *ue_ctx) -ue_ctx_t* -s1ap::find_ue_ctx(uint32_t mme_ue_s1ap_id) -{ - std::map::iterator it = m_active_ues.find(mme_ue_s1ap_id); - if(it == m_active_ues.end()) - { - return NULL; - } - else - { - return it->second; - } -} -void -s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) -{ - ue_ctx_t *ue_ptr = new ue_ctx_t; - memcpy(ue_ptr,&ue_ctx,sizeof(ue_ctx)); - m_active_ues.insert(std::pair(ue_ptr->mme_ue_s1ap_id,ue_ptr)); - - std::map::iterator it_enb = m_sctp_to_enb_id.find(ue_ptr->enb_sri.sinfo_assoc_id); - uint16_t enb_id = it_enb->second; - std::map >::iterator it_ue_id = m_enb_id_to_ue_ids.find(enb_id); - if(it_ue_id==m_enb_id_to_ue_ids.end()) - { - m_s1ap_log->error("Could not find eNB's UEs\n"); - return; - } - it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); - return; -} uint32_t s1ap::get_next_mme_ue_s1ap_id() From 336af1ed93da8489305349b09bba439761cd16ad Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 5 Feb 2018 12:26:23 +0000 Subject: [PATCH 013/143] Adding functions to get context from IMSI or MME UE S1AP Id. --- srsepc/hdr/mme/s1ap.h | 7 +++-- srsepc/src/mme/s1ap.cc | 65 +++++++++++++++++++++++++++++++++--------- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index fc4dd3d49..0f4be8d9b 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -81,6 +81,8 @@ public: void add_new_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo* enb_sri); ue_ctx_t* find_ue_ctx(uint32_t mme_ue_s1ap_id); void add_new_ue_ctx(const ue_ctx_t &ue_ctx); + ue_ctx_t* find_ue_ctx_from_imsi(uint64_t imsi); + ue_ctx_t* find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id); bool delete_ue_ctx(ue_ctx_t *ue_ctx); uint32_t allocate_m_tmsi(uint32_t mme_ue_s1ap_id); @@ -107,12 +109,13 @@ private: int m_s1mme; std::map m_active_enbs; std::map m_sctp_to_enb_id; - std::map m_active_ues; + std::map m_imsi_to_ue_ctx; + std::map m_mme_ue_s1ap_id_to_imsi; std::map > m_enb_id_to_ue_ids; uint32_t m_next_mme_ue_s1ap_id; uint32_t m_next_m_tmsi; - //FIXME the GTP-C should be moved to the MME class, the the packaging of GTP-C messages is done. + //FIXME the GTP-C should be moved to the MME class, when the packaging of GTP-C messages is done. mme_gtpc *m_mme_gtpc; }; diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index d91b4c4c5..877912e8d 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -120,16 +120,19 @@ s1ap::stop() return; } - - - - int s1ap::get_s1_mme() { return m_s1mme; } +uint32_t +s1ap::get_next_mme_ue_s1ap_id() +{ + return m_next_mme_ue_s1ap_id++; +} + + int s1ap::enb_listen() { @@ -246,7 +249,7 @@ s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, stru ssize_t n_sent = sctp_send(m_s1mme,reply_buffer->msg, reply_buffer->N_bytes, enb_sri, 0); if(n_sent == -1) { - m_s1ap_log->console("Failed to send S1 Setup Setup Reply\n"); + m_s1ap_log->console("Failed to send S1AP Initiating Message Reply\n"); m_pool->deallocate(reply_buffer); return false; } @@ -327,6 +330,31 @@ s1ap::delete_enb_ctx(int32_t assoc_id) //UE Context Management void s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) +{ + ue_ctx_t *ue_ptr = new ue_ctx_t; + memcpy(ue_ptr,&ue_ctx,sizeof(ue_ctx)); + + //This map will store the context of previously registered UEs + m_imsi_to_ue_ctx.insert(std::pair(ue_ptr->imsi,ue_ptr)); + + //This will map UE's MME S1AP Id to the UE's IMSI, when they are not in the EMM-DERGISTERED state. + m_mme_ue_s1ap_id_to_imsi.insert(std::pair(ue_ptr->mme_ue_s1ap_id,ue_ptr->imsi)); + + //Store which enb currently holds the UE + std::map::iterator it_enb = m_sctp_to_enb_id.find(ue_ptr->enb_sri.sinfo_assoc_id); + uint16_t enb_id = it_enb->second; + std::map >::iterator it_ue_id = m_enb_id_to_ue_ids.find(enb_id); + if(it_ue_id==m_enb_id_to_ue_ids.end()) + { + m_s1ap_log->error("Could not find eNB's UEs\n"); + return; + } + it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); + +} + /* +void +s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) { ue_ctx_t *ue_ptr = new ue_ctx_t; memcpy(ue_ptr,&ue_ctx,sizeof(ue_ctx)); @@ -343,12 +371,12 @@ s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); return; } - + */ ue_ctx_t* -s1ap::find_ue_ctx(uint32_t mme_ue_s1ap_id) +s1ap::find_ue_ctx_from_imsi(uint64_t imsi) { - std::map::iterator it = m_active_ues.find(mme_ue_s1ap_id); - if(it == m_active_ues.end()) + std::map::iterator it = m_imsi_to_ue_ctx.find(imsi); + if(it == m_imsi_to_ue_ctx.end()) { return NULL; } @@ -358,6 +386,19 @@ s1ap::find_ue_ctx(uint32_t mme_ue_s1ap_id) } } +ue_ctx_t* +s1ap::find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) +{ + std::map::iterator imsi_it = m_mme_ue_s1ap_id_to_imsi.find(mme_ue_s1ap_id); + if(imsi_it == m_mme_ue_s1ap_id_to_imsi.find(mme_ue_s1ap_id)) + { + return NULL; + } + else + { + return find_ue_ctx_from_imsi(imsi_it->second); + } +} void s1ap::delete_ues_in_enb(uint16_t enb_id) { @@ -417,11 +458,7 @@ s1ap::delete_ue_ctx(ue_ctx_t *ue_ctx) -uint32_t -s1ap::get_next_mme_ue_s1ap_id() -{ - return m_next_mme_ue_s1ap_id++; -} + void s1ap::activate_eps_bearer(uint32_t mme_s1ap_id, uint8_t ebi) From a0d727166ff5007db9c8b88695ff7ada1617e80e Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 5 Feb 2018 13:11:03 +0000 Subject: [PATCH 014/143] Starting to split EMM and ECM context. --- srsepc/hdr/mme/s1ap_common.h | 19 +++++++++++++ srsepc/src/mme/s1ap.cc | 55 ++++++++++++++++++++++++------------ 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index 2d693eba9..b252df586 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -127,6 +127,25 @@ typedef struct{ srslte::gtpc_f_teid_ie sgw_ctrl_fteid; } erab_ctx_t; +typedef struct{ + uint64_t imsi; + LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT guti; + emm_state_t emm_state; + eps_security_ctx_t security_ctxt; + uint8_t procedure_transaction_id; +} ue_emm_ctx_t; + +typedef struct{ + uint32_t enb_ue_s1ap_id; + uint32_t mme_ue_s1ap_id; + uint16_t enb_id; + struct sctp_sndrcvinfo enb_sri; + ecm_state_t ecm_state; + bool eit; + erab_ctx_t erabs_ctx[MAX_ERABS_PER_UE]; +} ue_esm_ctx_t; + + typedef struct{ uint64_t imsi; uint32_t enb_ue_s1ap_id; diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 877912e8d..0db79a8fb 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -399,26 +399,9 @@ s1ap::find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) return find_ue_ctx_from_imsi(imsi_it->second); } } -void -s1ap::delete_ues_in_enb(uint16_t enb_id) -{ - //delete UEs ctx - std::map >::iterator ues_in_enb = m_enb_id_to_ue_ids.find(enb_id); - std::set::iterator ue_id = ues_in_enb->second.begin(); - while(ue_id != ues_in_enb->second.end() ) - { - std::map::iterator ue_ctx = m_active_ues.find(*ue_id); - m_s1ap_log->info("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); - m_s1ap_log->console("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); - delete ue_ctx->second; //delete UE context - m_active_ues.erase(ue_ctx); //remove from general MME map - ues_in_enb->second.erase(ue_id++); //erase from the eNB's UE set - } - -} bool -s1ap::delete_ue_ctx(ue_ctx_t *ue_ctx) +s1ap::delete_ue_esm_ctx(uint32_t mme_ue_s1ap_id) { uint32_t mme_ue_s1ap_id = ue_ctx->mme_ue_s1ap_id; std::map::iterator ue_ctx_it = m_active_ues.find(mme_ue_s1ap_id); @@ -451,6 +434,42 @@ s1ap::delete_ue_ctx(ue_ctx_t *ue_ctx) return true; } +void +s1ap::delete_ues_esm_ctx_in_enb(uint16_t enb_id) +{ + //delete UEs ctx + std::map >::iterator ues_in_enb = m_enb_id_to_ue_ids.find(enb_id); + std::set::iterator ue_id = ues_in_enb->second.begin(); + while(ue_id != ues_in_enb->second.end() ) + { + std::map::iterator ue_ctx = m_active_ues.find(*ue_id); + m_s1ap_log->info("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); + m_s1ap_log->console("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); + delete ue_ctx->second; //delete UE context + m_active_ues.erase(ue_ctx); //remove from general MME map + ues_in_enb->second.erase(ue_id++); //erase from the eNB's UE set + } +} + +void +s1ap::delete_ues_in_enb(uint16_t enb_id) +{ + //delete UEs ctx + std::map >::iterator ues_in_enb = m_enb_id_to_ue_ids.find(enb_id); + std::set::iterator ue_id = ues_in_enb->second.begin(); + while(ue_id != ues_in_enb->second.end() ) + { + std::map::iterator ue_ctx = m_active_ues.find(*ue_id); + m_s1ap_log->info("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); + m_s1ap_log->console("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); + delete ue_ctx->second; //delete UE context + m_active_ues.erase(ue_ctx); //remove from general MME map + ues_in_enb->second.erase(ue_id++); //erase from the eNB's UE set + } + +} + + From d9da1f84f01244b0a66ccadf65c9c61fe67e1c87 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 5 Feb 2018 15:33:16 +0000 Subject: [PATCH 015/143] Continuing to separate EMM and ECM context --- srsepc/hdr/mme/s1ap.h | 18 ++++-- srsepc/hdr/mme/s1ap_common.h | 2 +- srsepc/src/mme/s1ap.cc | 112 ++++++++++++++++++----------------- 3 files changed, 73 insertions(+), 59 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 0f4be8d9b..9e23868e8 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -79,11 +79,17 @@ public: uint32_t get_next_mme_ue_s1ap_id(); enb_ctx_t* find_enb_ctx(uint16_t enb_id); void add_new_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo* enb_sri); + ue_ctx_t* find_ue_ctx(uint32_t mme_ue_s1ap_id); void add_new_ue_ctx(const ue_ctx_t &ue_ctx); - ue_ctx_t* find_ue_ctx_from_imsi(uint64_t imsi); - ue_ctx_t* find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id); - bool delete_ue_ctx(ue_ctx_t *ue_ctx); + + void add_new_ue_emm_ctx(const ue_emm_ctx_t &ue_emm_ctx); + void add_new_ue_ecm_ctx(const ue_ecm_ctx_t &ue_ecm_ctx); + ue_emm_ctx_t* find_ue_emm_ctx_from_imsi(uint64_t imsi); + ue_ecm_ctx_t* find_ue_ecm_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id); + bool delete_ue_emm_ctx(ue_emm_ctx_t *ue_emm_ctx); + bool delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id); + void delete_ues_ecm_ctx_in_enb(uint16_t enb_id); uint32_t allocate_m_tmsi(uint32_t mme_ue_s1ap_id); @@ -109,9 +115,11 @@ private: int m_s1mme; std::map m_active_enbs; std::map m_sctp_to_enb_id; - std::map m_imsi_to_ue_ctx; - std::map m_mme_ue_s1ap_id_to_imsi; std::map > m_enb_id_to_ue_ids; + + std::map m_imsi_to_ue_emm_ctx; + std::map m_mme_ue_s1ap_id_to_ue_ecm_ctx; + uint32_t m_next_mme_ue_s1ap_id; uint32_t m_next_m_tmsi; diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index b252df586..7a76f7eb9 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -143,7 +143,7 @@ typedef struct{ ecm_state_t ecm_state; bool eit; erab_ctx_t erabs_ctx[MAX_ERABS_PER_UE]; -} ue_esm_ctx_t; +} ue_ecm_ctx_t; typedef struct{ diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 0db79a8fb..0b2379571 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -328,6 +328,38 @@ s1ap::delete_enb_ctx(int32_t assoc_id) //UE Context Management + +void +s1ap::add_new_ue_emm_ctx(const ue_emm_ctx_t &ue_emm_ctx) +{ + ue_emm_ctx_t *ue_ptr = new ue_emm_ctx_t; + memcpy(ue_ptr,&ue_emm_ctx,sizeof(ue_emm_ctx)); + + //This map will store UEs EMM context + m_imsi_to_ue_emm_ctx.insert(std::pair(ue_ptr->imsi,ue_ptr)); +} + +void +s1ap::add_new_ue_ecm_ctx(const ue_ecm_ctx_t &ue_ecm_ctx) +{ + ue_ecm_ctx_t *ue_ptr = new ue_ecm_ctx_t; + memcpy(ue_ptr,&ue_ecm_ctx,sizeof(ue_ecm_ctx)); + + //This map will store UE's ECM context. + m_mme_ue_s1ap_id_to_ue_ecm_ctx.insert(std::pair(ue_ptr->mme_ue_s1ap_id,ue_ptr)); + //Store which enb currently holds the UE + std::map::iterator it_enb = m_sctp_to_enb_id.find(ue_ptr->enb_sri.sinfo_assoc_id); + uint16_t enb_id = it_enb->second; + std::map >::iterator it_ue_id = m_enb_id_to_ue_ids.find(enb_id); + if(it_ue_id==m_enb_id_to_ue_ids.end()) + { + m_s1ap_log->error("Could not find eNB's UEs\n"); + return; + } + it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); +} + + /* void s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) { @@ -351,7 +383,7 @@ s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) } it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); -} +}*/ /* void s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) @@ -372,11 +404,11 @@ s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) return; } */ -ue_ctx_t* -s1ap::find_ue_ctx_from_imsi(uint64_t imsi) +ue_emm_ctx_t* +s1ap::find_ue_emm_ctx_from_imsi(uint64_t imsi) { - std::map::iterator it = m_imsi_to_ue_ctx.find(imsi); - if(it == m_imsi_to_ue_ctx.end()) + std::map::iterator it = m_imsi_to_ue_emm_ctx.find(imsi); + if(it == m_imsi_to_ue_emm_ctx.end()) { return NULL; } @@ -386,33 +418,33 @@ s1ap::find_ue_ctx_from_imsi(uint64_t imsi) } } -ue_ctx_t* -s1ap::find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) +ue_ecm_ctx_t* +s1ap::find_ue_ecm_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) { - std::map::iterator imsi_it = m_mme_ue_s1ap_id_to_imsi.find(mme_ue_s1ap_id); - if(imsi_it == m_mme_ue_s1ap_id_to_imsi.find(mme_ue_s1ap_id)) + std::map::iterator it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_ue_s1ap_id); + if(it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) { return NULL; } else { - return find_ue_ctx_from_imsi(imsi_it->second); + return it->second; } } bool -s1ap::delete_ue_esm_ctx(uint32_t mme_ue_s1ap_id) +s1ap::delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id) { - uint32_t mme_ue_s1ap_id = ue_ctx->mme_ue_s1ap_id; - std::map::iterator ue_ctx_it = m_active_ues.find(mme_ue_s1ap_id); - if(ue_ctx_it == m_active_ues.end() ) + std::map::iterator ue_ecm_ctx_it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_ue_s1ap_id); + if(ue_ecm_ctx_it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) { - m_s1ap_log->info("UE not found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + m_s1ap_log->info("Cannot delete UE ECM context, UE not found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); return false; } + ue_ecm_ctx_t* ue_ecm_ctx = ue_ecm_ctx_it->second; //Delete UE within eNB UE set - std::map::iterator it = m_sctp_to_enb_id.find(ue_ctx->enb_sri.sinfo_assoc_id); + std::map::iterator it = m_sctp_to_enb_id.find(ue_ecm_ctx->enb_sri.sinfo_assoc_id); if(it == m_sctp_to_enb_id.end() ) { m_s1ap_log->error("Could not find eNB for this request.\n"); @@ -428,67 +460,41 @@ s1ap::delete_ue_esm_ctx(uint32_t mme_ue_s1ap_id) ue_set->second.erase(mme_ue_s1ap_id); //Delete UE context - delete ue_ctx; - m_active_ues.erase(ue_ctx_it); + m_mme_ue_s1ap_id_to_ue_ecm_ctx.erase(ue_ecm_ctx_it); + delete ue_ecm_ctx; m_s1ap_log->info("Deleted UE Context.\n"); return true; } -void -s1ap::delete_ues_esm_ctx_in_enb(uint16_t enb_id) -{ - //delete UEs ctx - std::map >::iterator ues_in_enb = m_enb_id_to_ue_ids.find(enb_id); - std::set::iterator ue_id = ues_in_enb->second.begin(); - while(ue_id != ues_in_enb->second.end() ) - { - std::map::iterator ue_ctx = m_active_ues.find(*ue_id); - m_s1ap_log->info("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); - m_s1ap_log->console("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); - delete ue_ctx->second; //delete UE context - m_active_ues.erase(ue_ctx); //remove from general MME map - ues_in_enb->second.erase(ue_id++); //erase from the eNB's UE set - } -} void -s1ap::delete_ues_in_enb(uint16_t enb_id) +s1ap::delete_ues_ecm_ctx_in_enb(uint16_t enb_id) { //delete UEs ctx std::map >::iterator ues_in_enb = m_enb_id_to_ue_ids.find(enb_id); std::set::iterator ue_id = ues_in_enb->second.begin(); while(ue_id != ues_in_enb->second.end() ) { - std::map::iterator ue_ctx = m_active_ues.find(*ue_id); - m_s1ap_log->info("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); - m_s1ap_log->console("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); + std::map::iterator ue_ctx = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(*ue_id); + m_s1ap_log->info("Deleting UE context. UE-MME S1AP Id: %d\n", ue_ctx->second->mme_ue_s1ap_id); + m_s1ap_log->console("Deleting UE context. UE-MME S1AP Id: %d\n", ue_ctx->second->mme_ue_s1ap_id); + m_mme_ue_s1ap_id_to_ue_ecm_ctx.erase(ue_ctx); //remove from general MME map delete ue_ctx->second; //delete UE context - m_active_ues.erase(ue_ctx); //remove from general MME map ues_in_enb->second.erase(ue_id++); //erase from the eNB's UE set } - } - - - - - - - - - - +//UE Bearer Managment void s1ap::activate_eps_bearer(uint32_t mme_s1ap_id, uint8_t ebi) { - std::map::iterator ue_ctx_it = m_active_ues.find(mme_s1ap_id); - if(ue_ctx_it == m_active_ues.end()) + std::map::iterator ue_ctx_it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_s1ap_id); + if(ue_ctx_it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) { m_s1ap_log->error("Could not find UE context\n"); return; } - ue_ctx_t * ue_ctx = ue_ctx_it->second; + ue_ecm_ctx_t * ue_ctx = ue_ctx_it->second; if (ue_ctx->erabs_ctx[ebi].state != ERAB_CTX_SETUP) { m_s1ap_log->error("EPS Bearer could not be activated. MME S1AP Id %d, EPS Bearer id %d, state %d\n",mme_s1ap_id,ebi,ue_ctx->erabs_ctx[ebi].state); From 085830d9107df225121a7f2048cc8ece6242b712 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 5 Feb 2018 15:55:41 +0000 Subject: [PATCH 016/143] Changing delete functions to delete both EMM and ECM context. --- srsepc/src/mme/s1ap.cc | 69 ++++++++++-------------------------------- 1 file changed, 16 insertions(+), 53 deletions(-) diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 0b2379571..d421191d5 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -103,16 +103,24 @@ s1ap::stop() if (m_s1mme != -1){ close(m_s1mme); } - std::map::iterator it = m_active_enbs.begin(); - while(it!=m_active_enbs.end()) + std::map::iterator enb_it = m_active_enbs.begin(); + while(enb_it!=m_active_enbs.end()) { - m_s1ap_log->info("Deleting eNB context. eNB Id: 0x%x\n", it->second->enb_id); - m_s1ap_log->console("Deleting eNB context. eNB Id: 0x%x\n", it->second->enb_id); - delete_ues_in_enb(it->second->enb_id); - delete it->second; - m_active_enbs.erase(it++); + m_s1ap_log->info("Deleting eNB context. eNB Id: 0x%x\n", enb_it->second->enb_id); + m_s1ap_log->console("Deleting eNB context. eNB Id: 0x%x\n", enb_it->second->enb_id); + delete_ues_ecm_ctx_in_enb(enb_it->second->enb_id); + delete enb_it->second; + m_active_enbs.erase(enb_it++); } + std::map::iterator ue_it = m_imsi_to_ue_emm_ctx.begin(); + while(ue_it!=m_imsi_to_ue_emm_ctx.end()) + { + m_s1ap_log->info("Deleting UE EMM context. IMSI: %015lu\n", ue_it->first); + m_s1ap_log->console("Deleting UE EMM context. IMSI: %015lu\n", ue_it->first); + delete ue_it->second; + m_imsi_to_ue_emm_ctx.erase(ue_it++); + } //Cleanup message handlers s1ap_mngmt_proc::cleanup(); s1ap_nas_transport::cleanup(); @@ -317,7 +325,7 @@ s1ap::delete_enb_ctx(int32_t assoc_id) m_s1ap_log->console("Deleting eNB context. eNB Id: 0x%x\n", enb_id); //Delete connected UEs ctx - delete_ues_in_enb(enb_id); + delete_ues_ecm_ctx_in_enb(enb_id); //Delete eNB delete it_ctx->second; @@ -328,7 +336,6 @@ s1ap::delete_enb_ctx(int32_t assoc_id) //UE Context Management - void s1ap::add_new_ue_emm_ctx(const ue_emm_ctx_t &ue_emm_ctx) { @@ -359,51 +366,7 @@ s1ap::add_new_ue_ecm_ctx(const ue_ecm_ctx_t &ue_ecm_ctx) it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); } - /* -void -s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) -{ - ue_ctx_t *ue_ptr = new ue_ctx_t; - memcpy(ue_ptr,&ue_ctx,sizeof(ue_ctx)); - - //This map will store the context of previously registered UEs - m_imsi_to_ue_ctx.insert(std::pair(ue_ptr->imsi,ue_ptr)); - - //This will map UE's MME S1AP Id to the UE's IMSI, when they are not in the EMM-DERGISTERED state. - m_mme_ue_s1ap_id_to_imsi.insert(std::pair(ue_ptr->mme_ue_s1ap_id,ue_ptr->imsi)); - - //Store which enb currently holds the UE - std::map::iterator it_enb = m_sctp_to_enb_id.find(ue_ptr->enb_sri.sinfo_assoc_id); - uint16_t enb_id = it_enb->second; - std::map >::iterator it_ue_id = m_enb_id_to_ue_ids.find(enb_id); - if(it_ue_id==m_enb_id_to_ue_ids.end()) - { - m_s1ap_log->error("Could not find eNB's UEs\n"); - return; - } - it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); - -}*/ - /* -void -s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) -{ - ue_ctx_t *ue_ptr = new ue_ctx_t; - memcpy(ue_ptr,&ue_ctx,sizeof(ue_ctx)); - m_active_ues.insert(std::pair(ue_ptr->mme_ue_s1ap_id,ue_ptr)); - std::map::iterator it_enb = m_sctp_to_enb_id.find(ue_ptr->enb_sri.sinfo_assoc_id); - uint16_t enb_id = it_enb->second; - std::map >::iterator it_ue_id = m_enb_id_to_ue_ids.find(enb_id); - if(it_ue_id==m_enb_id_to_ue_ids.end()) - { - m_s1ap_log->error("Could not find eNB's UEs\n"); - return; - } - it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); - return; -} - */ ue_emm_ctx_t* s1ap::find_ue_emm_ctx_from_imsi(uint64_t imsi) { From 1df3f0419260cefabbbdc3fe91207865772eb384 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 5 Feb 2018 18:06:19 +0000 Subject: [PATCH 017/143] Changing handle nas security mode complete. --- srsepc/hdr/mme/s1ap_common.h | 1 + srsepc/hdr/mme/s1ap_nas_transport.h | 16 ++--- srsepc/src/mme/s1ap_nas_transport.cc | 101 +++++++++++++++------------ 3 files changed, 67 insertions(+), 51 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index 7a76f7eb9..bf07a7c70 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -136,6 +136,7 @@ typedef struct{ } ue_emm_ctx_t; typedef struct{ + uint64_t imsi; uint32_t enb_ue_s1ap_id; uint32_t mme_ue_s1ap_id; uint16_t enb_id; diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index e37ce4d61..3e897c0a4 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -65,19 +65,19 @@ public: srslte::byte_buffer_t *reply_buffer, bool* reply_flag, struct sctp_sndrcvinfo *enb_sri); - bool handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag); - bool handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); - bool handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); - bool handle_esm_information_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); - bool handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); - bool handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); + bool handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag); + bool handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); + bool handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); + bool handle_esm_information_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); + bool handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); + bool handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); bool pack_authentication_request(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t next_mme_ue_s1ap_id, uint8_t *autn,uint8_t *rand); bool pack_authentication_reject(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id); bool unpack_authentication_response(LIBLTE_S1AP_MESSAGE_UPLINKNASTRANSPORT_STRUCT *ul_xport, LIBLTE_MME_AUTHENTICATION_RESPONSE_MSG_STRUCT *auth_resp); - bool pack_security_mode_command(srslte::byte_buffer_t *reply_msg, ue_ctx_t *ue_ctx); - bool pack_esm_information_request(srslte::byte_buffer_t *reply_msg, ue_ctx_t *ue_ctx); + bool pack_security_mode_command(srslte::byte_buffer_t *reply_msg, ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx); + bool pack_esm_information_request(srslte::byte_buffer_t *reply_msg, ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx); bool pack_attach_accept(ue_ctx_t *ue_ctx, LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctxt, struct srslte::gtpc_pdn_address_allocation_ie *paa, srslte::byte_buffer_t *nas_buffer); bool pack_identity_request(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index a200369a7..ae84b328b 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -135,14 +135,12 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA uint32_t enb_ue_s1ap_id = ul_xport->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID; uint32_t mme_ue_s1ap_id = ul_xport->MME_UE_S1AP_ID.MME_UE_S1AP_ID; - ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx(mme_ue_s1ap_id); - if(ue_ctx == NULL) + ue_ecm_ctx_t *ue_ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); + if(ue_ecm_ctx == NULL) { - //TODO UE not registered, send error message. - m_s1ap_log->warning("Received uplink NAS, but could not find UE context. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); + m_s1ap_log->warning("Received uplink NAS, but could not find UE ECM context. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); return false; } - m_s1ap_log->debug("Received uplink NAS and found UE. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); //Get NAS message type @@ -157,39 +155,37 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE: m_s1ap_log->info("Uplink NAS: Received Authentication Response\n"); m_s1ap_log->console("Uplink NAS: Received Authentication Response\n"); - handle_nas_authentication_response(nas_msg, ue_ctx, reply_buffer, reply_flag); + handle_nas_authentication_response(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); break; case LIBLTE_MME_MSG_TYPE_SECURITY_MODE_COMPLETE: m_s1ap_log->info("Uplink NAS: Received Security Mode Complete\n"); m_s1ap_log->console("Uplink NAS: Received Security Mode Complete\n"); - handle_nas_security_mode_complete(nas_msg, ue_ctx, reply_buffer, reply_flag); + handle_nas_security_mode_complete(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); break; case LIBLTE_MME_MSG_TYPE_ATTACH_COMPLETE: m_s1ap_log->info("Uplink NAS: Received Attach Complete\n"); m_s1ap_log->console("Uplink NAS: Received Attach Complete\n"); - handle_nas_attach_complete(nas_msg, ue_ctx, reply_buffer, reply_flag); - ue_ctx->security_ctxt.ul_nas_count++; + handle_nas_attach_complete(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); break; case LIBLTE_MME_MSG_TYPE_ESM_INFORMATION_RESPONSE: m_s1ap_log->info("Uplink NAS: Received ESM Information Response\n"); m_s1ap_log->console("Uplink NAS: Received ESM Information Response\n"); - handle_esm_information_response(nas_msg, ue_ctx, reply_buffer, reply_flag); - ue_ctx->security_ctxt.ul_nas_count++; + handle_esm_information_response(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); break; case LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE: m_s1ap_log->info("Uplink NAS: Received Identity Response\n"); m_s1ap_log->console("Uplink NAS: Received Identity Response\n"); - handle_identity_response(nas_msg, ue_ctx, reply_buffer, reply_flag); - //ue_ctx->security_ctxt.ul_nas_count++; + handle_identity_response(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); break; case LIBLTE_MME_MSG_TYPE_TRACKING_AREA_UPDATE_REQUEST: m_s1ap_log->info("UL NAS: Tracking Area Update Request\n"); - handle_tracking_area_update_request(nas_msg, ue_ctx, reply_buffer, reply_flag); + handle_tracking_area_update_request(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); break; default: m_s1ap_log->warning("Unhandled NAS message 0x%x\n", msg_type ); m_s1ap_log->console("Unhandled NAS message 0x%x\n", msg_type ); - return false; //FIXME (nas_msg deallocate needs to be called) + m_pool->deallocate(nas_msg); + return false; } if(*reply_flag == true) @@ -421,13 +417,19 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, } bool -s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag) +s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag) { LIBLTE_MME_AUTHENTICATION_RESPONSE_MSG_STRUCT auth_resp; bool ue_valid=true; - m_s1ap_log->console("Authentication Response -- IMSI %015lu\n", ue_ctx->imsi); + ue_emm_ctx_t *ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); + if(ue_emm_ctx == NULL) + { + m_s1ap_log->error("Authentication Response -- Could not find UE EMM context.\n"); + return false; + } + m_s1ap_log->console("Authentication Response -- IMSI %015lu\n", ue_emm_ctx->imsi); //Get NAS authentication response LIBLTE_ERROR_ENUM err = liblte_mme_unpack_authentication_response_msg((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &auth_resp); @@ -444,7 +446,7 @@ s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *na for(int i=0; i<8;i++) { - if(auth_resp.res[i] != ue_ctx->security_ctxt.xres[i]) + if(auth_resp.res[i] != ue_emm_ctx->security_ctxt.xres[i]) { ue_valid = false; } @@ -455,14 +457,14 @@ s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *na std::cout<<"XRES: "; for(int i=0;i<8;i++) { - std::cout << std::hex <<(uint16_t)ue_ctx->security_ctxt.xres[i]; + std::cout << std::hex <<(uint16_t)ue_emm_ctx->security_ctxt.xres[i]; } std::cout<console("UE Authentication Rejected.\n"); m_s1ap_log->warning("UE Authentication Rejected.\n"); //Send back Athentication Reject - pack_authentication_reject(reply_buffer, ue_ctx->enb_ue_s1ap_id, ue_ctx->mme_ue_s1ap_id); + pack_authentication_reject(reply_buffer, ue_ecm_ctx->enb_ue_s1ap_id, ue_ecm_ctx->mme_ue_s1ap_id); *reply_flag = true; m_s1ap_log->console("Downlink NAS: Sending Authentication Reject.\n"); return false; @@ -472,7 +474,7 @@ s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *na m_s1ap_log->console("UE Authentication Accepted.\n"); m_s1ap_log->info("UE Authentication Accepted.\n"); //Send Security Mode Command - pack_security_mode_command(reply_buffer, ue_ctx); + pack_security_mode_command(reply_buffer, ue_emm_ctx, ue_ecm_ctx); *reply_flag = true; m_s1ap_log->console("Downlink NAS: Sending NAS Security Mode Command.\n"); } @@ -480,8 +482,16 @@ s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *na } bool -s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) +s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) { + + ue_emm_ctx_t *ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); + if(ue_emm_ctx == NULL) + { + m_s1ap_log->error("Could not find UE's EMM context\n"); + return false; + } + LIBLTE_MME_SECURITY_MODE_COMPLETE_MSG_STRUCT sm_comp; //Get NAS authentication response @@ -499,11 +509,11 @@ s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas m_s1ap_log->warning("IMEI-SV present but not handled"); } - m_s1ap_log->info("Security Mode Command Complete -- IMSI: %lu\n", ue_ctx->imsi); - m_s1ap_log->console("Security Mode Command Complete -- IMSI: %lu\n", ue_ctx->imsi); - if(ue_ctx->eit == true) + m_s1ap_log->info("Security Mode Command Complete -- IMSI: %lu\n", ue_ecm_ctx->imsi); + m_s1ap_log->console("Security Mode Command Complete -- IMSI: %lu\n", ue_ecm_ctx->imsi); + if(ue_ecm_ctx->eit == true) { - pack_esm_information_request(reply_buffer, ue_ctx); + pack_esm_information_request(reply_buffer, ue_emm_ctx, ue_ecm_ctx); m_s1ap_log->console("Sending ESM information request\n"); *reply_flag = true; } @@ -511,7 +521,7 @@ s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas { //FIXME The packging of GTP-C messages is not ready. //This means that GTP-U tunnels are created with function calls, as opposed to GTP-C. - m_mme_gtpc->send_create_session_request(ue_ctx->imsi, ue_ctx->mme_ue_s1ap_id); + m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi, ue_ecm_ctx->mme_ue_s1ap_id); *reply_flag = false; //No reply needed } return true; @@ -830,7 +840,7 @@ s1ap_nas_transport::unpack_authentication_response(LIBLTE_S1AP_MESSAGE_UPLINKNAS } bool -s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, ue_ctx_t *ue_ctx) +s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx) { srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); @@ -888,7 +898,6 @@ s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, //Generate MAC for integrity protection //FIXME Write wrapper to support EIA1, EIA2, etc. - //TODO which is the RB ID? Standard says a constant, but which? uint8_t mac[4]; srslte::security_generate_k_nas( ue_ctx->security_ctxt.k_asme, @@ -925,7 +934,7 @@ s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, } bool -s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_msg, ue_ctx_t *ue_ctx) +s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_msg, ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx) { srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); @@ -943,14 +952,14 @@ s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_ms //Setup Dw NAS structure LIBLTE_S1AP_MESSAGE_DOWNLINKNASTRANSPORT_STRUCT *dw_nas = &init->choice.DownlinkNASTransport; dw_nas->ext=false; - dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ctx->mme_ue_s1ap_id;//FIXME Change name - dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ctx->enb_ue_s1ap_id; + dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ecm_ctx->mme_ue_s1ap_id;//FIXME Change name + dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ecm_ctx->enb_ue_s1ap_id; dw_nas->HandoverRestrictionList_present=false; dw_nas->SubscriberProfileIDforRFP_present=false; LIBLTE_MME_ESM_INFORMATION_REQUEST_MSG_STRUCT esm_info_req; esm_info_req.eps_bearer_id=0; - esm_info_req.proc_transaction_id = ue_ctx->procedure_transaction_id; + esm_info_req.proc_transaction_id = ue_emm_ctx->procedure_transaction_id; uint8_t sec_hdr_type=2; ue_ctx->security_ctxt.dl_nas_count++; @@ -964,8 +973,8 @@ s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_ms } uint8_t mac[4]; - srslte::security_128_eia1 (&ue_ctx->security_ctxt.k_nas_int[16], - ue_ctx->security_ctxt.dl_nas_count, + srslte::security_128_eia1 (&ue_emm_ctx->security_ctxt.k_nas_int[16], + ue_emm_ctx->security_ctxt.dl_nas_count, 0, SECURITY_DIRECTION_DOWNLINK, &nas_buffer->msg[5], @@ -1210,24 +1219,30 @@ s1ap_nas_transport::pack_emm_information(srslte::byte_buffer_t *reply_msg, uint3 emm_info.net_dst_present = false; //Integrity check - ue_ctx_t * ue_ctx = m_s1ap->find_ue_ctx(mme_ue_s1ap_id); - if(ue_ctx == NULL) + ue_ecm_ctx_t * ue_ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); + if(ue_ecm_ctx == NULL) + { + return false; + } + ue_emm_ctx_t * ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); + if(ue_emm_ctx == NULL) { return false; } + uint8_t sec_hdr_type =2; - ue_ctx->security_ctxt.dl_nas_count++; - LIBLTE_ERROR_ENUM err = liblte_mme_pack_emm_information_msg(&emm_info, sec_hdr_type, ue_ctx->security_ctxt.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); + ue_emm_ctx->security_ctxt.dl_nas_count++; + LIBLTE_ERROR_ENUM err = liblte_mme_pack_emm_information_msg(&emm_info, sec_hdr_type, ue_emm_ctx->security_ctxt.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); if(err != LIBLTE_SUCCESS) { - m_s1ap_log->error("Error packing Identity Request\n"); - m_s1ap_log->console("Error packing Identity REquest\n"); + m_s1ap_log->error("Error packing EMM Information\n"); + m_s1ap_log->console("Error packing EMM Information\n"); return false; } uint8_t mac[4]; - srslte::security_128_eia1 (&ue_ctx->security_ctxt.k_nas_int[16], - ue_ctx->security_ctxt.dl_nas_count, + srslte::security_128_eia1 (&ue_emm_ctx->security_ctxt.k_nas_int[16], + ue_emm_ctx->security_ctxt.dl_nas_count, 0, SECURITY_DIRECTION_DOWNLINK, &nas_buffer->msg[5], From 97f60ae6ff71ceafbb576298de9b9aef942079df Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 6 Feb 2018 12:19:18 +0000 Subject: [PATCH 018/143] starting to change handle_attach_request to support separate EMM and ECM context. --- srsepc/hdr/mme/s1ap_common.h | 3 +- srsepc/src/mme/s1ap_nas_transport.cc | 149 ++++++++++++--------------- 2 files changed, 66 insertions(+), 86 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index bf07a7c70..7e12f8ed4 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -130,9 +130,10 @@ typedef struct{ typedef struct{ uint64_t imsi; LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT guti; - emm_state_t emm_state; eps_security_ctx_t security_ctxt; uint8_t procedure_transaction_id; + emm_state_t emm_state; + uint32_t mme_ue_s1ap_id; } ue_emm_ctx_t; typedef struct{ diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index ae84b328b..3e0817dbc 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -240,42 +240,49 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, uint8_t rand[16]; uint8_t xres[8]; - ue_ctx_t ue_ctx; - ue_ctx.imsi = 0; - ue_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; - ue_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + + ue_emm_ctx_t ue_emm_ctx; + ue_ecm_ctx_t ue_ecm_ctx; + + //Set UE's EMM context + ue_emm_ctx.imsi = 0; + for(int i=0;i<=14;i++){ + ue_emm_ctx.imsi += attach_req.eps_mobile_id.imsi[i]*std::pow(10,14-i); + } + ue_emm_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); //Save UE network capabilities - memcpy(&ue_ctx.security_ctxt.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); - ue_ctx.security_ctxt.ms_network_cap_present = attach_req.ms_network_cap_present; + memcpy(&ue_emm_ctx.security_ctxt.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); + ue_emm_ctx.security_ctxt.ms_network_cap_present = attach_req.ms_network_cap_present; if(attach_req.ms_network_cap_present) { - memcpy(&ue_ctx.security_ctxt.ms_network_cap, &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); + memcpy(&ue_emm_ctx.security_ctxt.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 - ue_ctx.procedure_transaction_id = pdn_con_req.proc_transaction_id; + ue_emm_ctx.procedure_transaction_id = pdn_con_req.proc_transaction_id; - //Save whether ESM information transfer is necessary - ue_ctx.eit = pdn_con_req.esm_info_transfer_flag_present; - //m_s1ap_log->console("EPS Bearer id: %d\n", eps_bearer_id); //Initialize NAS count - ue_ctx.security_ctxt.ul_nas_count = 0; - ue_ctx.security_ctxt.dl_nas_count = 0; + ue_emm_ctx.security_ctxt.ul_nas_count = 0; + ue_emm_ctx.security_ctxt.dl_nas_count = 0; + + + //Set UE ECM context + //Set eNB information + ue_ecm_ctx.enb_id = enb_ue_s1ap_id; + memcpy(&ue_ecm_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + + //Save whether ESM information transfer is necessary + ue_ecm_ctx.eit = pdn_con_req.esm_info_transfer_flag_present; + //Add eNB info to UE ctxt - memcpy(&ue_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); //Initialize E-RABs for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) { - ue_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED; - ue_ctx.erabs_ctx[i].erab_id = i; - } - - //IMSI style attach - ue_ctx.imsi = 0; - for(int i=0;i<=14;i++){ - ue_ctx.imsi += attach_req.eps_mobile_id.imsi[i]*std::pow(10,14-i); + ue_ecm_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED; + ue_ecm_ctx.erabs_ctx[i].erab_id = i; } + //Log Attach Request information m_s1ap_log->console("Attach request -- IMSI: %015lu\n", ue_ctx.imsi); m_s1ap_log->info("Attach request -- IMSI: %015lu\n", ue_ctx.imsi); m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ue_ctx.enb_ue_s1ap_id, ue_ctx.mme_ue_s1ap_id); @@ -528,7 +535,7 @@ s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas } bool -s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) +s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { LIBLTE_MME_ATTACH_COMPLETE_MSG_STRUCT attach_comp; @@ -559,12 +566,12 @@ s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, u m_s1ap_log->error("EPS Bearer ID out of range\n"); return false; } - m_mme_gtpc->send_modify_bearer_request(&ue_ctx->erabs_ctx[act_bearer.eps_bearer_id]); + m_mme_gtpc->send_modify_bearer_request(&ue_ecm_ctx->erabs_ctx[act_bearer.eps_bearer_id]); return true; } bool -s1ap_nas_transport::handle_esm_information_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) +s1ap_nas_transport::handle_esm_information_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { LIBLTE_MME_ESM_INFORMATION_RESPONSE_MSG_STRUCT esm_info_resp; @@ -583,12 +590,12 @@ s1ap_nas_transport::handle_esm_information_response(srslte::byte_buffer_t *nas_m //FIXME The packging of GTP-C messages is not ready. //This means that GTP-U tunnels are created with function calls, as opposed to GTP-C. - m_mme_gtpc->send_create_session_request(ue_ctx->imsi, ue_ctx->mme_ue_s1ap_id); + m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi, ue_ecm_ctx->mme_ue_s1ap_id); return true; } bool -s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) +s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { uint8_t autn[16]; uint8_t rand[16]; @@ -607,10 +614,13 @@ s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ } m_s1ap_log->info("Id Response -- IMSI: %015lu\n", imsi); m_s1ap_log->console("Id Response -- IMSI: %015lu\n", imsi); - ue_ctx->imsi = imsi; + ue_ecm_ctx->imsi = imsi; + + //Get UE EMM context + ue_emm_ctx_t ue_emm_ctx; //Get Authentication Vectors from HSS - if(!m_hss->gen_auth_info_answer(imsi, ue_ctx->security_ctxt.k_asme, autn, rand, ue_ctx->security_ctxt.xres)) + if(!m_hss->gen_auth_info_answer(imsi, ue_emm_ctx.security_ctxt.k_asme, autn, rand, ue_emm_ctx.security_ctxt.xres)) { m_s1ap_log->console("User not found. IMSI %015lu\n",imsi); m_s1ap_log->info("User not found. IMSI %015lu\n",imsi); @@ -618,7 +628,7 @@ s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ } //Pack NAS Authentication Request in Downlink NAS Transport msg - pack_authentication_request(reply_msg, ue_ctx->enb_ue_s1ap_id, ue_ctx->mme_ue_s1ap_id, autn, rand); + pack_authentication_request(reply_msg, ue_ecm_ctx->enb_ue_s1ap_id, ue_ecm_ctx->mme_ue_s1ap_id, autn, rand); //Send reply to eNB *reply_flag = true; @@ -631,7 +641,7 @@ s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ bool -s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) +s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { /* @@ -657,45 +667,14 @@ s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *n //Setup Dw NAS structure LIBLTE_S1AP_MESSAGE_DOWNLINKNASTRANSPORT_STRUCT *dw_nas = &init->choice.DownlinkNASTransport; dw_nas->ext=false; - dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ctx->mme_ue_s1ap_id; - dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ctx->enb_ue_s1ap_id; + dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ecm_ctx->mme_ue_s1ap_id; + dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ecm_ctx->enb_ue_s1ap_id; dw_nas->HandoverRestrictionList_present=false; dw_nas->SubscriberProfileIDforRFP_present=false; - m_s1ap_log->console("Tracking area accept to MME-UE S1AP Id %d\n", ue_ctx->mme_ue_s1ap_id); + m_s1ap_log->console("Tracking area accept to MME-UE S1AP Id %d\n", ue_ecm_ctx->mme_ue_s1ap_id); LIBLTE_MME_TRACKING_AREA_UPDATE_ACCEPT_MSG_STRUCT tau_acc; - /*typedef struct{ - LIBLTE_MME_GPRS_TIMER_STRUCT t3412; - LIBLTE_MME_EPS_MOBILE_ID_STRUCT guti; - LIBLTE_MME_TRACKING_AREA_IDENTITY_LIST_STRUCT tai_list; - LIBLTE_MME_EPS_BEARER_CONTEXT_STATUS_STRUCT eps_bearer_context_status; - LIBLTE_MME_LOCATION_AREA_ID_STRUCT lai; - LIBLTE_MME_MOBILE_ID_STRUCT ms_id; - LIBLTE_MME_GPRS_TIMER_STRUCT t3402; - LIBLTE_MME_GPRS_TIMER_STRUCT t3423; - LIBLTE_MME_PLMN_LIST_STRUCT equivalent_plmns; - LIBLTE_MME_EMERGENCY_NUMBER_LIST_STRUCT emerg_num_list; - LIBLTE_MME_EPS_NETWORK_FEATURE_SUPPORT_STRUCT eps_network_feature_support; - LIBLTE_MME_GPRS_TIMER_3_STRUCT t3412_ext; - LIBLTE_MME_ADDITIONAL_UPDATE_RESULT_ENUM additional_update_result; - uint8 eps_update_result; - uint8 emm_cause; - bool t3412_present; - bool guti_present; - bool tai_list_present; - bool eps_bearer_context_status_present; - bool lai_present; - bool ms_id_present; - bool emm_cause_present; - bool t3402_present; - bool t3423_present; - bool equivalent_plmns_present; - bool emerg_num_list_present; - bool eps_network_feature_support_present; - bool additional_update_result_present; - bool t3412_ext_present; -}LIBLTE_MME_TRACKING_AREA_UPDATE_ACCEPT_MSG_STRUCT; -*/ + //Send reply to eNB //*reply_flag = true; @@ -858,8 +837,8 @@ s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, //Setup Dw NAS structure LIBLTE_S1AP_MESSAGE_DOWNLINKNASTRANSPORT_STRUCT *dw_nas = &init->choice.DownlinkNASTransport; dw_nas->ext=false; - dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ctx->mme_ue_s1ap_id; - dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ctx->enb_ue_s1ap_id; + dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ecm_ctx->mme_ue_s1ap_id; + dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ecm_ctx->enb_ue_s1ap_id; dw_nas->HandoverRestrictionList_present=false; dw_nas->SubscriberProfileIDforRFP_present=false; @@ -873,14 +852,14 @@ s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, sm_cmd.nas_ksi.nas_ksi=0; //Replay UE security cap - memcpy(sm_cmd.ue_security_cap.eea,ue_ctx->security_ctxt.ue_network_cap.eea,8*sizeof(bool)); - memcpy(sm_cmd.ue_security_cap.eia,ue_ctx->security_ctxt.ue_network_cap.eia,8*sizeof(bool)); - sm_cmd.ue_security_cap.uea_present = ue_ctx->security_ctxt.ue_network_cap.uea_present; - memcpy(sm_cmd.ue_security_cap.uea,ue_ctx->security_ctxt.ue_network_cap.uea,8*sizeof(bool)); - sm_cmd.ue_security_cap.uia_present = ue_ctx->security_ctxt.ue_network_cap.uia_present; - memcpy(sm_cmd.ue_security_cap.uia,ue_ctx->security_ctxt.ue_network_cap.uia,8*sizeof(bool)); - sm_cmd.ue_security_cap.gea_present = ue_ctx->security_ctxt.ms_network_cap_present; - memcpy(sm_cmd.ue_security_cap.gea,ue_ctx->security_ctxt.ms_network_cap.gea,8*sizeof(bool)); + memcpy(sm_cmd.ue_security_cap.eea,ue_emm_ctx->security_ctxt.ue_network_cap.eea,8*sizeof(bool)); + memcpy(sm_cmd.ue_security_cap.eia,ue_emm_ctx->security_ctxt.ue_network_cap.eia,8*sizeof(bool)); + sm_cmd.ue_security_cap.uea_present = ue_emm_ctx->security_ctxt.ue_network_cap.uea_present; + memcpy(sm_cmd.ue_security_cap.uea,ue_emm_ctx->security_ctxt.ue_network_cap.uea,8*sizeof(bool)); + sm_cmd.ue_security_cap.uia_present = ue_emm_ctx->security_ctxt.ue_network_cap.uia_present; + memcpy(sm_cmd.ue_security_cap.uia,ue_emm_ctx->security_ctxt.ue_network_cap.uia,8*sizeof(bool)); + sm_cmd.ue_security_cap.gea_present = ue_emm_ctx->security_ctxt.ms_network_cap_present; + memcpy(sm_cmd.ue_security_cap.gea,ue_emm_ctx->security_ctxt.ms_network_cap.gea,8*sizeof(bool)); sm_cmd.imeisv_req_present=false; sm_cmd.nonce_ue_present=false; @@ -888,8 +867,8 @@ s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, uint8_t sec_hdr_type=3; - ue_ctx->security_ctxt.dl_nas_count = 0; - LIBLTE_ERROR_ENUM err = liblte_mme_pack_security_mode_command_msg(&sm_cmd,sec_hdr_type, ue_ctx->security_ctxt.dl_nas_count,(LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); + ue_emm_ctx->security_ctxt.dl_nas_count = 0; + LIBLTE_ERROR_ENUM err = liblte_mme_pack_security_mode_command_msg(&sm_cmd,sec_hdr_type, ue_emm_ctx->security_ctxt.dl_nas_count,(LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); if(err != LIBLTE_SUCCESS) { m_s1ap_log->console("Error packing Athentication Request\n"); @@ -900,15 +879,15 @@ s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, //FIXME Write wrapper to support EIA1, EIA2, etc. uint8_t mac[4]; - srslte::security_generate_k_nas( ue_ctx->security_ctxt.k_asme, + srslte::security_generate_k_nas( ue_emm_ctx->security_ctxt.k_asme, srslte::CIPHERING_ALGORITHM_ID_EEA0, srslte::INTEGRITY_ALGORITHM_ID_128_EIA1, - ue_ctx->security_ctxt.k_nas_enc, - ue_ctx->security_ctxt.k_nas_int + ue_emm_ctx->security_ctxt.k_nas_enc, + ue_emm_ctx->security_ctxt.k_nas_int ); - srslte::security_128_eia1 (&ue_ctx->security_ctxt.k_nas_int[16], - ue_ctx->security_ctxt.dl_nas_count, + srslte::security_128_eia1 (&ue_emm_ctx->security_ctxt.k_nas_int[16], + ue_emm_ctx->security_ctxt.dl_nas_count, 0, SECURITY_DIRECTION_DOWNLINK, &nas_buffer->msg[5], @@ -962,9 +941,9 @@ s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_ms esm_info_req.proc_transaction_id = ue_emm_ctx->procedure_transaction_id; uint8_t sec_hdr_type=2; - ue_ctx->security_ctxt.dl_nas_count++; + ue_emm_ctx->security_ctxt.dl_nas_count++; - LIBLTE_ERROR_ENUM err = srslte_mme_pack_esm_information_request_msg(&esm_info_req, sec_hdr_type,ue_ctx->security_ctxt.dl_nas_count,(LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); + LIBLTE_ERROR_ENUM err = srslte_mme_pack_esm_information_request_msg(&esm_info_req, sec_hdr_type,ue_emm_ctx->security_ctxt.dl_nas_count,(LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); if(err != LIBLTE_SUCCESS) { m_s1ap_log->error("Error packing ESM information request\n"); From 7306d00ea52cb5429998575b61696332a93d2a56 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 6 Feb 2018 12:58:47 +0000 Subject: [PATCH 019/143] Changed attach request handling for separate EMM and ECM context. --- srsepc/src/mme/s1ap_nas_transport.cc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 3e0817dbc..98d89e507 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -267,11 +267,13 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, //Set UE ECM context + ue_ecm_ctx.imsi = ue_emm_ctx.imsi; + ue_ecm_ctx.mme_ue_s1ap_id = ue_emm_ctx.mme_ue_s1ap_id; //Set eNB information ue_ecm_ctx.enb_id = enb_ue_s1ap_id; memcpy(&ue_ecm_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); - //Save whether ESM information transfer is necessary + //Save whether secure ESM information transfer is necessary ue_ecm_ctx.eit = pdn_con_req.esm_info_transfer_flag_present; //Add eNB info to UE ctxt @@ -283,9 +285,9 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, } //Log Attach Request information - m_s1ap_log->console("Attach request -- IMSI: %015lu\n", ue_ctx.imsi); - m_s1ap_log->info("Attach request -- IMSI: %015lu\n", ue_ctx.imsi); - m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ue_ctx.enb_ue_s1ap_id, ue_ctx.mme_ue_s1ap_id); + m_s1ap_log->console("Attach request -- IMSI: %015lu\n", ue_emm_ctx.imsi); + m_s1ap_log->info("Attach request -- IMSI: %015lu\n", ue_emm_ctx.imsi); + m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ue_ecm_ctx.enb_ue_s1ap_id, ue_ecm_ctx.mme_ue_s1ap_id); m_s1ap_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], @@ -310,16 +312,18 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, m_s1ap_log->console("PDN Connectivity Request -- ESM Information Transfer requested: %s\n", pdn_con_req.esm_info_transfer_flag_present ? "true" : "false"); //Get Authentication Vectors from HSS - if(!m_hss->gen_auth_info_answer(ue_ctx.imsi, ue_ctx.security_ctxt.k_asme, autn, rand, ue_ctx.security_ctxt.xres)) + if(!m_hss->gen_auth_info_answer(ue_emm_ctx.imsi, ue_emm_ctx.security_ctxt.k_asme, autn, rand, ue_emm_ctx.security_ctxt.xres)) { - m_s1ap_log->console("User not found. IMSI %015lu\n",ue_ctx.imsi); - m_s1ap_log->info("User not found. IMSI %015lu\n",ue_ctx.imsi); + m_s1ap_log->console("User not found. IMSI %015lu\n",ue_emm_ctx.imsi); + m_s1ap_log->info("User not found. IMSI %015lu\n",ue_emm_ctx.imsi); return false; } - m_s1ap->add_new_ue_ctx(ue_ctx); + m_s1ap->add_new_ue_emm_ctx(ue_emm_ctx); + m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); + //Pack NAS Authentication Request in Downlink NAS Transport msg - pack_authentication_request(reply_buffer, ue_ctx.enb_ue_s1ap_id, ue_ctx.mme_ue_s1ap_id, autn, rand); + pack_authentication_request(reply_buffer, ue_ecm_ctx.enb_ue_s1ap_id, ue_ecm_ctx.mme_ue_s1ap_id, autn, rand); //Send reply to eNB *reply_flag = true; From 7c21b4cc111db7a9dd4947daee5255b60dbcb27c Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 6 Feb 2018 14:37:39 +0000 Subject: [PATCH 020/143] changing handle of guti attach request. --- srsepc/src/mme/s1ap_nas_transport.cc | 51 ++++++++++++++++------------ 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 98d89e507..6095535fc 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -346,38 +346,44 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, if(it == m_s1ap->m_tmsi_to_s1ap_id.end()) { //Could not find IMSI from M-TMSI, send Id request - ue_ctx_t ue_ctx; - ue_ctx.imsi = 0; - ue_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; - ue_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + ue_emm_ctx_t tmp_ue_emm_ctx; + ue_ecm_ctx_t ue_ecm_ctx; + + //Set tmp UE EMM context + tmp_ue_emm_ctx.imsi = 0; //Save UE network capabilities - memcpy(&ue_ctx.security_ctxt.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); - ue_ctx.security_ctxt.ms_network_cap_present = attach_req.ms_network_cap_present; + memcpy(&tmp_ue_emm_ctx.security_ctxt.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); + tmp_ue_emm_ctx.security_ctxt.ms_network_cap_present = attach_req.ms_network_cap_present; if(attach_req.ms_network_cap_present) { - memcpy(&ue_ctx.security_ctxt.ms_network_cap, &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); + memcpy(&tmp_ue_emm_ctx.security_ctxt.ms_network_cap, &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); } + //Initialize NAS count + tmp_ue_emm_ctx.security_ctxt.ul_nas_count = 0; + tmp_ue_emm_ctx.security_ctxt.dl_nas_count = 0; + tmp_ue_emm_ctx.procedure_transaction_id = pdn_con_req.proc_transaction_id; + + //Set ECM context + ue_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; + ue_ecm_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + uint8_t eps_bearer_id = pdn_con_req.eps_bearer_id; //TODO: Unused - ue_ctx.procedure_transaction_id = pdn_con_req.proc_transaction_id; //Save whether ESM information transfer is necessary - ue_ctx.eit = pdn_con_req.esm_info_transfer_flag_present; + ue_ecm_ctx.eit = pdn_con_req.esm_info_transfer_flag_present; //m_s1ap_log->console("EPS Bearer id: %d\n", eps_bearer_id); - //Initialize NAS count - ue_ctx.security_ctxt.ul_nas_count = 0; - ue_ctx.security_ctxt.dl_nas_count = 0; - //Add eNB info to UE ctxt - memcpy(&ue_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + //Add eNB info to UE ctxt + memcpy(&ue_ecm_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); //Initialize E-RABs for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) { - ue_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED; - ue_ctx.erabs_ctx[i].erab_id = i; + ue_ecm_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED; + ue_ecm_ctx.erabs_ctx[i].erab_id = i; } - m_s1ap_log->console("Attach request -- IMSI: %015lu\n", ue_ctx.imsi); - m_s1ap_log->info("Attach request -- IMSI: %015lu\n", ue_ctx.imsi); - m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ue_ctx.enb_ue_s1ap_id, ue_ctx.mme_ue_s1ap_id); + m_s1ap_log->console("Attach request -- IMSI: %015lu\n", ue_ecm_ctx.imsi); + m_s1ap_log->info("Attach request -- IMSI: %015lu\n", ue_ecm_ctx.imsi); + m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ue_ecm_ctx.enb_ue_s1ap_id, ue_ecm_ctx.mme_ue_s1ap_id); m_s1ap_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], @@ -403,13 +409,15 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, m_s1ap_log->console("Could not find M-TMSI=0x%x. Sending ID request\n",m_tmsi); m_s1ap_log->info("Could not find M-TMSI=0x%d. Sending Id Request\n", m_tmsi); - m_s1ap->add_new_ue_ctx(ue_ctx); - pack_identity_request(reply_buffer, ue_ctx.enb_ue_s1ap_id, ue_ctx.mme_ue_s1ap_id); + m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); + pack_identity_request(reply_buffer, ue_ecm_ctx.enb_ue_s1ap_id, ue_ecm_ctx.mme_ue_s1ap_id); *reply_flag = true; return true; } else{ + m_s1ap_log->console("Attach Request -- Found M-TMSI: %d\n",m_tmsi); + /* ue_ctx_t *ue_ctx_ptr = m_s1ap->find_ue_ctx(it->second); if(ue_ctx_ptr!=NULL) { @@ -423,6 +431,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, m_s1ap_log->error("Found M-TMSI but could not find UE context\n"); return false; } + */ } return true; } From 86adc29ce8453fe037052f7c0e98d250e40cb757 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 6 Feb 2018 16:23:41 +0000 Subject: [PATCH 021/143] Changing send initial context setup. --- srsepc/hdr/mme/s1ap_nas_transport.h | 2 +- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 34 ++++++++++++++++----------- srsepc/src/mme/s1ap_nas_transport.cc | 14 +++++------ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index 3e897c0a4..c38ae2bb3 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -79,7 +79,7 @@ public: bool pack_security_mode_command(srslte::byte_buffer_t *reply_msg, ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx); bool pack_esm_information_request(srslte::byte_buffer_t *reply_msg, ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx); - bool pack_attach_accept(ue_ctx_t *ue_ctx, LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctxt, struct srslte::gtpc_pdn_address_allocation_ie *paa, srslte::byte_buffer_t *nas_buffer); + bool pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx, LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctxt, struct srslte::gtpc_pdn_address_allocation_ie *paa, srslte::byte_buffer_t *nas_buffer); bool pack_identity_request(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id); bool pack_emm_information(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id); diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 1d6df8cf3..60d50e173 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -98,19 +98,25 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, m_s1ap_log->info("Preparing to send Initial Context Setup request\n"); //Find UE Context - ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx(mme_ue_s1ap_id); - if(ue_ctx == NULL) + ue_ecm_ctx_t *ue_ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); + if(ue_ecm_ctx == NULL) + { + m_s1ap_log->error("Could not find UE to send Setup Context Request. MME S1AP Id: %d", mme_ue_s1ap_id); + return false; + } + ue_emm_ctx_t *ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); + if(ue_emm_ctx == NULL) { m_s1ap_log->error("Could not find UE to send Setup Context Request. MME S1AP Id: %d", mme_ue_s1ap_id); return false; } //Add MME and eNB S1AP Ids - in_ctxt_req->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ctx->mme_ue_s1ap_id; - in_ctxt_req->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ctx->enb_ue_s1ap_id; + in_ctxt_req->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ecm_ctx->mme_ue_s1ap_id; + in_ctxt_req->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ecm_ctx->enb_ue_s1ap_id; //Set UE-AMBR - in_ctxt_req->uEaggregateMaximumBitrate.uEaggregateMaximumBitRateDL.BitRate=1000000000;//2^32-1 + in_ctxt_req->uEaggregateMaximumBitrate.uEaggregateMaximumBitRateDL.BitRate=1000000000; in_ctxt_req->uEaggregateMaximumBitrate.uEaggregateMaximumBitRateUL.BitRate=1000000000;//FIXME Get UE-AMBR from HSS //Setup eRAB context @@ -143,7 +149,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, bzero(in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer,sizeof(uint8_t)*16); for(int i = 0; i<3; i++) { - if(ue_ctx->security_ctxt.ue_network_cap.eea[i+1] == true) + if(ue_emm_ctx->security_ctxt.ue_network_cap.eea[i+1] == true) { in_ctxt_req->UESecurityCapabilities.encryptionAlgorithms.buffer[i] = 1; //EEA supported } @@ -151,7 +157,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, { in_ctxt_req->UESecurityCapabilities.encryptionAlgorithms.buffer[i] = 0; //EEA not supported } - if(ue_ctx->security_ctxt.ue_network_cap.eia[i+1] == true) + if(ue_emm_ctx->security_ctxt.ue_network_cap.eia[i+1] == true) { in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer[i] = 1; //EEA supported } @@ -162,9 +168,9 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, // in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer[0] = 1; //EIA1 } uint8_t key_enb[32]; - liblte_security_generate_k_enb(ue_ctx->security_ctxt.k_asme, ue_ctx->security_ctxt.ul_nas_count, key_enb); + liblte_security_generate_k_enb(ue_emm_ctx->security_ctxt.k_asme, ue_emm_ctx->security_ctxt.ul_nas_count, key_enb); liblte_unpack(key_enb, 32, in_ctxt_req->SecurityKey.buffer); - m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",ue_ctx->security_ctxt.ul_nas_count); + m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",ue_emm_ctx->security_ctxt.ul_nas_count); //Set Attach accepted and activat default bearer NAS messages if(cs_resp->paa_present != true) { @@ -177,7 +183,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, return false; } srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); - m_s1ap_nas_transport->pack_attach_accept(ue_ctx, erab_ctxt, &cs_resp->paa, nas_buffer); + m_s1ap_nas_transport->pack_attach_accept(ue_emm_ctx, ue_ecm_ctx, erab_ctxt, &cs_resp->paa, nas_buffer); LIBLTE_ERROR_ENUM err = liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)reply_buffer); @@ -187,7 +193,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, return false; } //Send Reply to eNB - ssize_t n_sent = sctp_send(s1mme,reply_buffer->msg, reply_buffer->N_bytes, &ue_ctx->enb_sri, 0); + ssize_t n_sent = sctp_send(s1mme,reply_buffer->msg, reply_buffer->N_bytes, &ue_ecm_ctx->enb_sri, 0); if(n_sent == -1) { m_s1ap_log->error("Failed to send Initial Context Setup Request\n"); @@ -195,9 +201,9 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, } //Change E-RAB state to Context Setup Requested and save S-GW control F-TEID - ue_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].state = ERAB_CTX_REQUESTED; - ue_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.teid = sgw_ctrl_fteid.teid; - ue_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.ipv4 = sgw_ctrl_fteid.ipv4; + ue_ecm_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].state = ERAB_CTX_REQUESTED; + ue_ecm_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.teid = sgw_ctrl_fteid.teid; + ue_ecm_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.ipv4 = sgw_ctrl_fteid.ipv4; struct in_addr addr; addr.s_addr = htonl(sgw_s1u_ip); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 6095535fc..6bbab6947 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -993,7 +993,7 @@ s1ap_nas_transport::pack_esm_information_request(srslte::byte_buffer_t *reply_ms } bool -s1ap_nas_transport::pack_attach_accept(ue_ctx_t *ue_ctx, LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctxt, struct srslte::gtpc_pdn_address_allocation_ie *paa, srslte::byte_buffer_t *nas_buffer) { +s1ap_nas_transport::pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx, LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctxt, struct srslte::gtpc_pdn_address_allocation_ie *paa, srslte::byte_buffer_t *nas_buffer) { LIBLTE_MME_ATTACH_ACCEPT_MSG_STRUCT attach_accept; LIBLTE_MME_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT act_def_eps_bearer_context_req; //bzero(&act_def_eps_bearer_context_req,sizeof(LIBLTE_MME_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT)); @@ -1040,7 +1040,7 @@ s1ap_nas_transport::pack_attach_accept(ue_ctx_t *ue_ctx, LIBLTE_S1AP_E_RABTOBESE attach_accept.guti.guti.mnc = mnc; attach_accept.guti.guti.mme_group_id = m_s1ap->m_s1ap_args.mme_group; attach_accept.guti.guti.mme_code = m_s1ap->m_s1ap_args.mme_code; - attach_accept.guti.guti.m_tmsi = m_s1ap->allocate_m_tmsi(ue_ctx->mme_ue_s1ap_id); + attach_accept.guti.guti.m_tmsi = m_s1ap->allocate_m_tmsi(ue_ecm_ctx->mme_ue_s1ap_id); m_s1ap_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, @@ -1077,7 +1077,7 @@ s1ap_nas_transport::pack_attach_accept(ue_ctx_t *ue_ctx, LIBLTE_S1AP_E_RABTOBESE //act_def_eps_bearer_context_req.apn std::string apn("test123"); act_def_eps_bearer_context_req.apn.apn = apn; //FIXME - act_def_eps_bearer_context_req.proc_transaction_id = ue_ctx->procedure_transaction_id; //FIXME + act_def_eps_bearer_context_req.proc_transaction_id = ue_emm_ctx->procedure_transaction_id; //FIXME //Set DNS server act_def_eps_bearer_context_req.protocol_cnfg_opts_present = true; @@ -1098,13 +1098,13 @@ s1ap_nas_transport::pack_attach_accept(ue_ctx_t *ue_ctx, LIBLTE_S1AP_E_RABTOBESE act_def_eps_bearer_context_req.esm_cause_present = false; uint8_t sec_hdr_type =2; - ue_ctx->security_ctxt.dl_nas_count++; + ue_emm_ctx->security_ctxt.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, ue_ctx->security_ctxt.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); + liblte_mme_pack_attach_accept_msg(&attach_accept, sec_hdr_type, ue_emm_ctx->security_ctxt.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); //Integrity protect NAS message uint8_t mac[4]; - srslte::security_128_eia1 (&ue_ctx->security_ctxt.k_nas_int[16], - ue_ctx->security_ctxt.dl_nas_count, + srslte::security_128_eia1 (&ue_emm_ctx->security_ctxt.k_nas_int[16], + ue_emm_ctx->security_ctxt.dl_nas_count, 0, SECURITY_DIRECTION_DOWNLINK, &nas_buffer->msg[5], From 0c013c19caf358b45051be25122829bdaf535642 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 6 Feb 2018 16:33:58 +0000 Subject: [PATCH 022/143] changed handle intial context setup response. --- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 60d50e173..4a31a0111 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -222,8 +222,8 @@ s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_I { uint32_t mme_ue_s1ap_id = in_ctxt_resp->MME_UE_S1AP_ID.MME_UE_S1AP_ID; - ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx(mme_ue_s1ap_id); - if (ue_ctx == NULL) + ue_ecm_ctx_t *ue_ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); + if (ue_ecm_ctx == NULL) { m_s1ap_log->error("Could not find UE's context in active UE's map\n"); return false; @@ -233,7 +233,7 @@ s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_I for(uint32_t i=0; iE_RABSetupListCtxtSURes.len;i++) { uint8_t erab_id = in_ctxt_resp->E_RABSetupListCtxtSURes.buffer[i].e_RAB_ID.E_RAB_ID; - erab_ctx_t *erab_ctx = &ue_ctx->erabs_ctx[erab_id]; + erab_ctx_t *erab_ctx = &ue_ecm_ctx->erabs_ctx[erab_id]; if (erab_ctx->state != ERAB_CTX_REQUESTED) { m_s1ap_log->error("E-RAB requested was not active %d\n",erab_id); From af927eb1d8d45ca5a4127e14c0439ee0ae1ce13e Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 6 Feb 2018 17:21:18 +0000 Subject: [PATCH 023/143] Changing handling of ue context release request. Compiling now, needs testing. --- srsepc/hdr/mme/mme_gtpc.h | 2 +- srsepc/src/mme/mme_gtpc.cc | 6 +++--- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 12 +++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index f2804e22b..402a52a99 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -52,7 +52,7 @@ public: void handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu); void send_modify_bearer_request(erab_ctx_t *bearer_ctx); void handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu); - void send_delete_session_request(ue_ctx_t *ue_ctx); + void send_delete_session_request(ue_ecm_ctx_t *ue_ecm_ctx); private: diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 4b396f7a8..6f4a1cdcc 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -219,7 +219,7 @@ mme_gtpc::handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu) } void -mme_gtpc::send_delete_session_request(ue_ctx_t *ue_ctx) +mme_gtpc::send_delete_session_request(ue_ecm_ctx_t *ue_ecm_ctx) { m_mme_gtpc_log->info("Sending GTP-C Delete Session Request request\n"); srslte::gtpc_pdu del_req_pdu; @@ -230,9 +230,9 @@ mme_gtpc::send_delete_session_request(ue_ctx_t *ue_ctx) for(int i = 0; ierabs_ctx[i].state != ERAB_DEACTIVATED) + if(ue_ecm_ctx->erabs_ctx[i].state != ERAB_DEACTIVATED) { - sgw_ctrl_fteid = &ue_ctx->erabs_ctx[i].sgw_ctrl_fteid; + sgw_ctrl_fteid = &ue_ecm_ctx->erabs_ctx[i].sgw_ctrl_fteid; break; } } diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 4a31a0111..3fce06de6 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -272,8 +272,8 @@ s1ap_ctx_mngmt_proc::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECON m_s1ap_log->info("Received UE Context Release Request. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); m_s1ap_log->console("Received UE Context Release Request. MME-UE S1AP Id %d\n", mme_ue_s1ap_id); - ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx(mme_ue_s1ap_id); - if(ue_ctx == NULL) + ue_ecm_ctx_t *ue_ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); + if(ue_ecm_ctx == NULL) { m_s1ap_log->info("UE not found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); return false; @@ -283,7 +283,7 @@ s1ap_ctx_mngmt_proc::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECON bool active = false; for(int i=0;ierabs_ctx[i].state != ERAB_DEACTIVATED) + if(ue_ecm_ctx->erabs_ctx[i].state != ERAB_DEACTIVATED) //FIXME use ECM state { active = true; //ue_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; @@ -293,14 +293,16 @@ s1ap_ctx_mngmt_proc::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECON if(active == true) { //There are active E-RABs, send delete session request - m_mme_gtpc->send_delete_session_request(ue_ctx); + m_mme_gtpc->send_delete_session_request(ue_ecm_ctx); } //m_s1ap->delete_ue_ctx(ue_ctx); for(int i=0;ierabs_ctx[i].state = ERAB_DEACTIVATED; + ue_ecm_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; } //Delete UE context + m_s1ap->delete_ue_ecm_ctx(ue_ecm_ctx->mme_ue_s1ap_id); + m_s1ap_log->info("Deleted UE Context.\n"); return true; } From 47b574a3bad5367438fda844b1c747a85bec4e3e Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 6 Feb 2018 18:59:53 +0000 Subject: [PATCH 024/143] Removed unused value in ECM ctx --- srsepc/hdr/mme/s1ap_common.h | 1 - srsepc/src/mme/s1ap_nas_transport.cc | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index 7e12f8ed4..84ced0637 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -140,7 +140,6 @@ typedef struct{ uint64_t imsi; uint32_t enb_ue_s1ap_id; uint32_t mme_ue_s1ap_id; - uint16_t enb_id; struct sctp_sndrcvinfo enb_sri; ecm_state_t ecm_state; bool eit; diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 6bbab6947..76719efbe 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -270,7 +270,7 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, ue_ecm_ctx.imsi = ue_emm_ctx.imsi; ue_ecm_ctx.mme_ue_s1ap_id = ue_emm_ctx.mme_ue_s1ap_id; //Set eNB information - ue_ecm_ctx.enb_id = enb_ue_s1ap_id; + ue_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; memcpy(&ue_ecm_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); //Save whether secure ESM information transfer is necessary From 95bc4f8b08eee99cdebbc6fd2af5e0c8a5f4b1af Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 7 Feb 2018 14:11:42 +0000 Subject: [PATCH 025/143] adding tmp emm storage for when the UE uses an unknown guti and id request has to be sent. --- srsepc/hdr/mme/s1ap.h | 4 ++++ srsepc/src/mme/s1ap.cc | 25 +++++++++++++++++++++++++ srsepc/src/mme/s1ap_nas_transport.cc | 27 ++++++++++----------------- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 9e23868e8..bb0140c57 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -91,6 +91,9 @@ public: bool delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id); void delete_ues_ecm_ctx_in_enb(uint16_t enb_id); + void store_tmp_ue_emm_ctx(const ue_emm_ctx_t &ue_ecm_ctx); + bool get_tmp_ue_emm_ctx(uint32_t mme_ue_s1ap_id, ue_emm_ctx_t* ue_emm_ptr); + uint32_t allocate_m_tmsi(uint32_t mme_ue_s1ap_id); s1ap_args_t m_s1ap_args; @@ -119,6 +122,7 @@ private: std::map m_imsi_to_ue_emm_ctx; std::map m_mme_ue_s1ap_id_to_ue_ecm_ctx; + std::map m_mme_ue_s1ap_id_to_tmp_ue_emm_ctx; uint32_t m_next_mme_ue_s1ap_id; uint32_t m_next_m_tmsi; diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index d421191d5..9a9ebafee 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -346,6 +346,31 @@ s1ap::add_new_ue_emm_ctx(const ue_emm_ctx_t &ue_emm_ctx) m_imsi_to_ue_emm_ctx.insert(std::pair(ue_ptr->imsi,ue_ptr)); } +void +s1ap::store_tmp_ue_emm_ctx(const ue_emm_ctx_t &tmp_ue_emm_ctx) +{ + ue_emm_ctx_t *ue_ptr = new ue_emm_ctx_t; + memcpy(ue_ptr,&tmp_ue_emm_ctx,sizeof(tmp_ue_emm_ctx)); + + //This map will store UE's ECM context. + m_mme_ue_s1ap_id_to_tmp_ue_emm_ctx.insert(std::pair(ue_ptr->mme_ue_s1ap_id,ue_ptr)); +} + +bool +s1ap::get_tmp_ue_emm_ctx(uint32_t mme_ue_s1ap_id, ue_emm_ctx_t* ue_emm_ptr) +{ + + std::map::iterator it = m_mme_ue_s1ap_id_to_tmp_ue_emm_ctx.find(mme_ue_s1ap_id); + if(it == m_mme_ue_s1ap_id_to_tmp_ue_emm_ctx.end() ) + { + return false; + } + memcpy(ue_emm_ptr, it->second,sizeof(ue_emm_ctx_t)); + delete it->second; + m_mme_ue_s1ap_id_to_tmp_ue_emm_ctx.erase(it); + return true; +} + void s1ap::add_new_ue_ecm_ctx(const ue_ecm_ctx_t &ue_ecm_ctx) { diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 76719efbe..4998f68e4 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -385,31 +385,24 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, m_s1ap_log->info("Attach request -- IMSI: %015lu\n", ue_ecm_ctx.imsi); m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ue_ecm_ctx.enb_ue_s1ap_id, ue_ecm_ctx.mme_ue_s1ap_id); m_s1ap_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]); + 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]); m_s1ap_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]); + 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]); m_s1ap_log->console("Attach Request -- MS Network Capabilities Present: %s\n", attach_req.ms_network_cap_present ? "true" : "false"); m_s1ap_log->console("PDN Connectivity Request -- EPS Bearer Identity requested: %d\n", pdn_con_req.eps_bearer_id); m_s1ap_log->console("PDN Connectivity Request -- Procedure Transaction Id: %d\n", pdn_con_req.proc_transaction_id); m_s1ap_log->console("PDN Connectivity Request -- ESM Information Transfer requested: %s\n", pdn_con_req.esm_info_transfer_flag_present ? "true" : "false"); m_s1ap_log->console("Could not find M-TMSI=0x%x. Sending ID request\n",m_tmsi); - m_s1ap_log->info("Could not find M-TMSI=0x%d. Sending Id Request\n", m_tmsi); + m_s1ap_log->info("Could not find M-TMSI=0x%x. Sending Id Request\n", m_tmsi); m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); + + //We do not know the IMSI of the UE yet + //This will be removed when the Identity request is received + m_s1ap->store_tmp_ue_emm_ctx(tmp_ue_emm_ctx); + pack_identity_request(reply_buffer, ue_ecm_ctx.enb_ue_s1ap_id, ue_ecm_ctx.mme_ue_s1ap_id); *reply_flag = true; return true; From fc1629a06ef8d58bb031ffec9aeddc2620718497 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 7 Feb 2018 16:53:09 +0000 Subject: [PATCH 026/143] Fixed bug with getting EMM context in handle identity request. Attach with unknown GUTI starting to work again. --- srsepc/src/mme/s1ap_nas_transport.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 4998f68e4..bb3f9008c 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -401,6 +401,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, //We do not know the IMSI of the UE yet //This will be removed when the Identity request is received + tmp_ue_emm_ctx.mme_ue_s1ap_id = ue_ecm_ctx.mme_ue_s1ap_id; m_s1ap->store_tmp_ue_emm_ctx(tmp_ue_emm_ctx); pack_identity_request(reply_buffer, ue_ecm_ctx.enb_ue_s1ap_id, ue_ecm_ctx.mme_ue_s1ap_id); @@ -624,7 +625,13 @@ s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ //Get UE EMM context ue_emm_ctx_t ue_emm_ctx; - + if(m_s1ap->get_tmp_ue_emm_ctx(ue_ecm_ctx->mme_ue_s1ap_id, &ue_emm_ctx) == false) + { + m_s1ap_log->error("Could not find UE's temporary EMM context. MME UE S1AP Id: %d\n",ue_ecm_ctx->mme_ue_s1ap_id); + return false; + } + ue_emm_ctx.imsi=imsi; + //Get Authentication Vectors from HSS if(!m_hss->gen_auth_info_answer(imsi, ue_emm_ctx.security_ctxt.k_asme, autn, rand, ue_emm_ctx.security_ctxt.xres)) { @@ -632,7 +639,9 @@ s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ m_s1ap_log->info("User not found. IMSI %015lu\n",imsi); return false; } - + //Store UE EMM context + m_s1ap->add_new_ue_emm_ctx(ue_emm_ctx); + //Pack NAS Authentication Request in Downlink NAS Transport msg pack_authentication_request(reply_msg, ue_ecm_ctx->enb_ue_s1ap_id, ue_ecm_ctx->mme_ue_s1ap_id, autn, rand); From 386e56ef4040a18c9356a6dfaefb9990660753a0 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 7 Feb 2018 18:13:51 +0000 Subject: [PATCH 027/143] Fixed bug when GUTI is unknown but EMM context was previously present. Added function to delete EMM context. --- srsepc/hdr/mme/s1ap.h | 2 +- srsepc/src/mme/s1ap.cc | 18 +++++++++++++++++- srsepc/src/mme/s1ap_nas_transport.cc | 10 ++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index bb0140c57..323e15df2 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -87,7 +87,7 @@ public: void add_new_ue_ecm_ctx(const ue_ecm_ctx_t &ue_ecm_ctx); ue_emm_ctx_t* find_ue_emm_ctx_from_imsi(uint64_t imsi); ue_ecm_ctx_t* find_ue_ecm_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id); - bool delete_ue_emm_ctx(ue_emm_ctx_t *ue_emm_ctx); + bool delete_ue_emm_ctx(uint64_t imsi); bool delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id); void delete_ues_ecm_ctx_in_enb(uint16_t enb_id); diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 9a9ebafee..4f526ed58 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -419,6 +419,22 @@ s1ap::find_ue_ecm_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) return it->second; } } +bool +s1ap::delete_ue_emm_ctx(uint64_t imsi) +{ + std::map::iterator ue_emm_ctx_it = m_imsi_to_ue_emm_ctx.find(imsi); + if(ue_emm_ctx_it == m_imsi_to_ue_emm_ctx.end()) + { + m_s1ap_log->info("Cannot delete UE EMM context, UE not found. IMSI: %d\n", imsi); + return false; + } + + //Delete UE context + m_imsi_to_ue_emm_ctx.erase(ue_emm_ctx_it); + delete ue_emm_ctx_it->second; + m_s1ap_log->info("Deleted UE EMM Context.\n"); + return true; +} bool s1ap::delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id) @@ -450,7 +466,7 @@ s1ap::delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id) //Delete UE context m_mme_ue_s1ap_id_to_ue_ecm_ctx.erase(ue_ecm_ctx_it); delete ue_ecm_ctx; - m_s1ap_log->info("Deleted UE Context.\n"); + m_s1ap_log->info("Deleted UE ECM Context.\n"); return true; } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index bb3f9008c..df33ecf3a 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -619,6 +619,16 @@ s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ for(int i=0;i<=14;i++){ imsi += id_resp.mobile_id.imsi[i]*std::pow(10,14-i); } + + //Check if EMM context already exists + ue_emm_ctx_t *ue_tmp_ptr = m_s1ap->find_ue_emm_ctx_from_imsi(imsi); + if(ue_tmp_ptr != NULL) + { + m_s1ap_log->warning("Unkonw GUTI, but UE's EMM context present.\n"); + m_s1ap->delete_ue_emm_ctx(imsi); + } + + m_s1ap_log->info("Id Response -- IMSI: %015lu\n", imsi); m_s1ap_log->console("Id Response -- IMSI: %015lu\n", imsi); ue_ecm_ctx->imsi = imsi; From 2cc717b5066c377d2d214150ebd5e2960c4d0de2 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 8 Feb 2018 13:57:30 +0000 Subject: [PATCH 028/143] Starting to check NAS intgrity of GUTI attach. --- srsepc/hdr/mme/s1ap.h | 4 ++-- srsepc/src/mme/s1ap.cc | 11 +++++----- srsepc/src/mme/s1ap_nas_transport.cc | 30 ++++++++++++++++++---------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 323e15df2..0025a2f39 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -94,7 +94,7 @@ public: void store_tmp_ue_emm_ctx(const ue_emm_ctx_t &ue_ecm_ctx); bool get_tmp_ue_emm_ctx(uint32_t mme_ue_s1ap_id, ue_emm_ctx_t* ue_emm_ptr); - uint32_t allocate_m_tmsi(uint32_t mme_ue_s1ap_id); + uint32_t allocate_m_tmsi(uint64_t imsi); s1ap_args_t m_s1ap_args; srslte::log_filter *m_s1ap_log; @@ -103,7 +103,7 @@ public: s1ap_nas_transport* m_s1ap_nas_transport; s1ap_ctx_mngmt_proc* m_s1ap_ctx_mngmt_proc; - std::map m_tmsi_to_s1ap_id; + std::map m_tmsi_to_s1ap_id; private: s1ap(); diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 4f526ed58..9e59d9545 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -38,7 +38,8 @@ boost::mutex s1ap_instance_mutex; s1ap::s1ap(): m_s1mme(-1), - m_next_mme_ue_s1ap_id(1) + m_next_mme_ue_s1ap_id(1), + m_next_m_tmsi(0xA000) { } @@ -512,11 +513,11 @@ s1ap::activate_eps_bearer(uint32_t mme_s1ap_id, uint8_t ebi) } uint32_t -s1ap::allocate_m_tmsi(uint32_t mme_ue_s1ap_id) +s1ap::allocate_m_tmsi(uint64_t imsi) { - //uint32_t m_tmsi = m_next_m_tmsi++; - //m_tmsi_to_s1ap_id.insert(std::pair(m_tmsi,mme_ue_s1ap_id)); - uint32_t m_tmsi = 0x0123; + uint32_t m_tmsi = m_next_m_tmsi++; + m_tmsi_to_s1ap_id.insert(std::pair(m_tmsi,imsi)); + //uint32_t m_tmsi = 0x0123; return m_tmsi; } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index df33ecf3a..27b6e4bb7 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -342,7 +342,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, { //GUTI style attach uint32_t m_tmsi = attach_req.eps_mobile_id.guti.m_tmsi; - std::map::iterator it = m_s1ap->m_tmsi_to_s1ap_id.find(m_tmsi); + std::map::iterator it = m_s1ap->m_tmsi_to_s1ap_id.find(m_tmsi); if(it == m_s1ap->m_tmsi_to_s1ap_id.end()) { //Could not find IMSI from M-TMSI, send Id request @@ -411,21 +411,31 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, else{ m_s1ap_log->console("Attach Request -- Found M-TMSI: %d\n",m_tmsi); - /* - ue_ctx_t *ue_ctx_ptr = m_s1ap->find_ue_ctx(it->second); - if(ue_ctx_ptr!=NULL) + //Get UE EMM context + ue_emm_ctx_t *ue_emm_ctx = find_ue_emm_ctx_from_imsi(it->second); + if(ue_emm_ctx_ptr!=NULL) { - m_s1ap_log->console("Found UE context. IMSI: %015lu\n",ue_ctx_ptr->imsi); - m_mme_gtpc->send_create_session_request(ue_ctx_ptr->imsi, ue_ctx_ptr->mme_ue_s1ap_id); - *reply_flag = false; //No reply needed - return true; + m_s1ap_log->console("Found UE context. IMSI: %015lu\n",ue_emm_ctx_ptr->imsi); + //Check NAS integrity + bool msg_valid = false; + + if(msg_valid == true) + { + //Create session request + m_mme_gtpc->send_create_session_request(ue_ctx_ptr->imsi, ue_ctx_ptr->mme_ue_s1ap_id); + *reply_flag = false; //No reply needed + return true; + } + else + { + //NAS integrity + } } else { m_s1ap_log->error("Found M-TMSI but could not find UE context\n"); return false; } - */ } return true; } @@ -1052,7 +1062,7 @@ s1ap_nas_transport::pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *u attach_accept.guti.guti.mnc = mnc; attach_accept.guti.guti.mme_group_id = m_s1ap->m_s1ap_args.mme_group; attach_accept.guti.guti.mme_code = m_s1ap->m_s1ap_args.mme_code; - attach_accept.guti.guti.m_tmsi = m_s1ap->allocate_m_tmsi(ue_ecm_ctx->mme_ue_s1ap_id); + attach_accept.guti.guti.m_tmsi = m_s1ap->allocate_m_tmsi(ue_emm_ctx->imsi); m_s1ap_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, From 3b90c71c661bfdc43b65736b7886d1eb7e0b6ceb Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 8 Feb 2018 14:08:02 +0000 Subject: [PATCH 029/143] changing a comment --- srsepc/src/mme/s1ap_nas_transport.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 27b6e4bb7..102c27e14 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -428,7 +428,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, } else { - //NAS integrity + //NAS integrity failed. Re-start quthentication process. } } else From 1bef5cebf67a0a906b72cabc8ff950115f0192f0 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 9 Feb 2018 10:29:40 +0000 Subject: [PATCH 030/143] small commit --- srsepc/hdr/mme/s1ap_nas_transport.h | 2 ++ srsepc/src/mme/s1ap_nas_transport.cc | 39 +++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index c38ae2bb3..b7a660e72 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -72,6 +72,8 @@ public: bool handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); bool handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); + bool integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu); + bool pack_authentication_request(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t next_mme_ue_s1ap_id, uint8_t *autn,uint8_t *rand); bool pack_authentication_reject(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id); bool unpack_authentication_response(LIBLTE_S1AP_MESSAGE_UPLINKNASTRANSPORT_STRUCT *ul_xport, LIBLTE_MME_AUTHENTICATION_RESPONSE_MSG_STRUCT *auth_resp); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 102c27e14..a917f133a 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -412,17 +412,17 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, m_s1ap_log->console("Attach Request -- Found M-TMSI: %d\n",m_tmsi); //Get UE EMM context - ue_emm_ctx_t *ue_emm_ctx = find_ue_emm_ctx_from_imsi(it->second); - if(ue_emm_ctx_ptr!=NULL) + ue_emm_ctx_t *ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(it->second); + if(ue_emm_ctx!=NULL) { - m_s1ap_log->console("Found UE context. IMSI: %015lu\n",ue_emm_ctx_ptr->imsi); + m_s1ap_log->console("Found UE context. IMSI: %015lu\n",ue_emm_ctx->imsi); //Check NAS integrity bool msg_valid = false; if(msg_valid == true) { //Create session request - m_mme_gtpc->send_create_session_request(ue_ctx_ptr->imsi, ue_ctx_ptr->mme_ue_s1ap_id); + m_mme_gtpc->send_create_session_request(ue_emm_ctx->imsi, ue_emm_ctx->mme_ue_s1ap_id); *reply_flag = false; //No reply needed return true; } @@ -717,6 +717,37 @@ s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *n } +bool +s1ap_nas_transport::integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu) +{ + uint8_t exp_mac[4]; + uint8_t *mac = &pdu->msg[1]; + int i; + + srslte::security_128_eia1(&emm_ctx->security_ctxt.k_nas_int[16], + emm_ctx->security_ctxt.ul_nas_count, + 0, + SECURITY_DIRECTION_UPLINK, + &pdu->msg[5], + pdu->N_bytes-5, + &exp_mac[0]); + + // Check if expected mac equals the sent mac + for(i=0; i<4; i++){ + if(exp_mac[i] != mac[i]){ + m_s1ap_log->warning("Integrity check failure. Local: count=%d, [%02x %02x %02x %02x], " + "Received: count=%d, [%02x %02x %02x %02x]\n", + emm_ctx->security_ctxt.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; + } + } + m_s1ap_log->info("Integrity check ok. Local: count=%d, Received: count=%d\n", + emm_ctx->security_ctxt.ul_nas_count, pdu->msg[5]); + return true; +} + + /*Packing/Unpacking helper functions*/ bool s1ap_nas_transport::pack_authentication_request(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t next_mme_ue_s1ap_id, uint8_t *autn, uint8_t *rand) From 3f7bea1af66111dcb75780c0dd1fc0bbad733687 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 12 Feb 2018 16:19:31 +0000 Subject: [PATCH 031/143] Starting to integrity check GUTI attach. Integrity failing for now. --- srsepc/hdr/mme/s1ap.h | 2 +- srsepc/hdr/mme/s1ap_nas_transport.h | 4 +- srsepc/src/mme/s1ap.cc | 3 +- srsepc/src/mme/s1ap_nas_transport.cc | 75 ++++++++++++++++++---------- 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 0025a2f39..4015f7c70 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -103,7 +103,7 @@ public: s1ap_nas_transport* m_s1ap_nas_transport; s1ap_ctx_mngmt_proc* m_s1ap_ctx_mngmt_proc; - std::map m_tmsi_to_s1ap_id; + std::map m_tmsi_to_imsi; private: s1ap(); diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index b7a660e72..8d9b7429a 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -48,8 +48,7 @@ public: bool handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRANSPORT_STRUCT *ul_xport, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool handle_nas_attach_request( uint32_t enb_ue_s1ap_id, - const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, - const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool* reply_flag, struct sctp_sndrcvinfo *enb_sri); @@ -62,6 +61,7 @@ public: bool handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool* reply_flag, struct sctp_sndrcvinfo *enb_sri); diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 9e59d9545..4cd6f421c 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -516,7 +516,8 @@ uint32_t s1ap::allocate_m_tmsi(uint64_t imsi) { uint32_t m_tmsi = m_next_m_tmsi++; - m_tmsi_to_s1ap_id.insert(std::pair(m_tmsi,imsi)); + m_tmsi_to_imsi.insert(std::pair(m_tmsi,imsi)); + m_s1ap_log->info("Allocated M-TMSI %d,\n"); //uint32_t m_tmsi = 0x0123; return m_tmsi; } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index a917f133a..bd4865d03 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -78,8 +78,7 @@ s1ap_nas_transport::init(void) bool s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *init_ue, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) { - LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT attach_req; - LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT pdn_con_req; + LIBLTE_MME_SERVICE_REQUEST_MSG_STRUCT service_req; m_s1ap_log->console("Received Initial UE Message.\n"); @@ -92,28 +91,16 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA log_unhandled_initial_ue_message_ies(init_ue); /*Check whether NAS Attach Request or Service Request*/ - uint8_t pd, msg_type; + bool mac_valid = false; + uint8_t pd, msg_type, sec_hdr_type; srslte::byte_buffer_t *nas_msg = m_pool->allocate(); memcpy(nas_msg->msg, &init_ue->NAS_PDU.buffer, init_ue->NAS_PDU.n_octets); nas_msg->N_bytes = init_ue->NAS_PDU.n_octets; + liblte_mme_parse_msg_header((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &pd, &msg_type); if(msg_type == LIBLTE_MME_MSG_TYPE_ATTACH_REQUEST) { - //Get NAS Attach Request and PDN connectivity request messages - LIBLTE_ERROR_ENUM err = liblte_mme_unpack_attach_request_msg((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &attach_req); - if(err != LIBLTE_SUCCESS){ - m_s1ap_log->error("Error unpacking NAS attach request. Error: %s\n", liblte_error_text[err]); - m_pool->deallocate(nas_msg); - return false; - } - /*Get PDN Connectivity Request*/ - err = liblte_mme_unpack_pdn_connectivity_request_msg(&attach_req.esm_msg, &pdn_con_req); - if(err != LIBLTE_SUCCESS){ - m_s1ap_log->error("Error unpacking NAS PDN Connectivity Request. Error: %s\n", liblte_error_text[err]); - m_pool->deallocate(nas_msg); - return false; - } - handle_nas_attach_request(enb_ue_s1ap_id, attach_req,pdn_con_req,reply_buffer,reply_flag, enb_sri); + handle_nas_attach_request(enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); } else if(msg_type == LIBLTE_MME_SECURITY_HDR_TYPE_SERVICE_REQUEST) { @@ -200,24 +187,57 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA bool s1ap_nas_transport::handle_nas_attach_request(uint32_t enb_ue_s1ap_id, - const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, - const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool* reply_flag, struct sctp_sndrcvinfo *enb_sri) { + LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT attach_req; + LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT pdn_con_req; + + //Get NAS Attach Request and PDN connectivity request messages + LIBLTE_ERROR_ENUM err = liblte_mme_unpack_attach_request_msg((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &attach_req); + if(err != LIBLTE_SUCCESS){ + m_s1ap_log->error("Error unpacking NAS attach request. Error: %s\n", liblte_error_text[err]); + m_pool->deallocate(nas_msg); + return false; + } + /*Get PDN Connectivity Request*/ + err = liblte_mme_unpack_pdn_connectivity_request_msg(&attach_req.esm_msg, &pdn_con_req); + if(err != LIBLTE_SUCCESS){ + m_s1ap_log->error("Error unpacking NAS PDN Connectivity Request. Error: %s\n", liblte_error_text[err]); + m_pool->deallocate(nas_msg); + return false; + } + + //Parse the message security header + uint8 pd = 0; + uint8 msg_type = 0; + uint8 sec_hdr_type = 0; + liblte_mme_parse_msg_sec_header((LIBLTE_BYTE_MSG_STRUCT*)nas_msg, &pd, &sec_hdr_type); + //Get attach type from attach request if(attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMSI) { m_s1ap_log->console("Attach Request -- IMSI-style attach request\n"); m_s1ap_log->info("Attach Request -- IMSI-style attach request\n"); + if(sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS) + { + m_s1ap_log->error("Attach request -- IMSI-stlye attach request is not plain NAS\n"); + return false; + } handle_nas_imsi_attach_request(enb_ue_s1ap_id, attach_req, pdn_con_req, reply_buffer, reply_flag, enb_sri); } else if(attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_GUTI) { m_s1ap_log->console("Attach Request -- GUTI-style attach request\n"); m_s1ap_log->info("Attach Request -- GUTI-style attach request\n"); - handle_nas_guti_attach_request(enb_ue_s1ap_id, attach_req, pdn_con_req, reply_buffer, reply_flag, enb_sri); + if(sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY) + { + m_s1ap_log->error("Attach request -- GUTI-stlye attach request is not integrity protected\n"); + return false; + } + handle_nas_guti_attach_request(enb_ue_s1ap_id, attach_req, pdn_con_req, nas_msg, reply_buffer, reply_flag, enb_sri); } else { @@ -333,17 +353,18 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, } bool -s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, +s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool* reply_flag, struct sctp_sndrcvinfo *enb_sri) { //GUTI style attach uint32_t m_tmsi = attach_req.eps_mobile_id.guti.m_tmsi; - std::map::iterator it = m_s1ap->m_tmsi_to_s1ap_id.find(m_tmsi); - if(it == m_s1ap->m_tmsi_to_s1ap_id.end()) + std::map::iterator it = m_s1ap->m_tmsi_to_imsi.find(m_tmsi); + if(it == m_s1ap->m_tmsi_to_imsi.end()) { //Could not find IMSI from M-TMSI, send Id request ue_emm_ctx_t tmp_ue_emm_ctx; @@ -411,6 +432,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, else{ m_s1ap_log->console("Attach Request -- Found M-TMSI: %d\n",m_tmsi); + m_s1ap_log->console("Attach Request -- IMSI: %d\n",it->second); //Get UE EMM context ue_emm_ctx_t *ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(it->second); if(ue_emm_ctx!=NULL) @@ -418,17 +440,18 @@ s1ap_nas_transport::handle_nas_guti_attach_request(uint32_t enb_ue_s1ap_id, m_s1ap_log->console("Found UE context. IMSI: %015lu\n",ue_emm_ctx->imsi); //Check NAS integrity bool msg_valid = false; - + msg_valid = integrity_check(ue_emm_ctx,nas_msg); if(msg_valid == true) { //Create session request + m_s1ap_log->console("GUTI Attach -- NAS Integrity OK."); m_mme_gtpc->send_create_session_request(ue_emm_ctx->imsi, ue_emm_ctx->mme_ue_s1ap_id); *reply_flag = false; //No reply needed return true; } else { - //NAS integrity failed. Re-start quthentication process. + //NAS integrity failed. Re-start authentication process. } } else From 26f782d8a48291f4d99d55f0872209fe280d44f0 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 13 Feb 2018 17:45:25 +0000 Subject: [PATCH 032/143] Starting to integrity check all Uplink NAS Transport messages. --- srsepc/src/mme/s1ap.cc | 4 +- srsepc/src/mme/s1ap_nas_transport.cc | 103 ++++++++++++++++++++++----- 2 files changed, 86 insertions(+), 21 deletions(-) diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 4cd6f421c..31db87cf5 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -74,7 +74,7 @@ s1ap::init(s1ap_args_t s1ap_args, srslte::log_filter *s1ap_log) m_s1ap_args = s1ap_args; srslte::s1ap_mccmnc_to_plmn(s1ap_args.mcc, s1ap_args.mnc, &m_plmn); - m_next_m_tmsi = rand(); + m_next_m_tmsi = 0xF000; //Init log m_s1ap_log = s1ap_log; @@ -517,7 +517,7 @@ s1ap::allocate_m_tmsi(uint64_t imsi) { uint32_t m_tmsi = m_next_m_tmsi++; m_tmsi_to_imsi.insert(std::pair(m_tmsi,imsi)); - m_s1ap_log->info("Allocated M-TMSI %d,\n"); + m_s1ap_log->info("Allocated M-TMSI 0x%x,\n",m_tmsi); //uint32_t m_tmsi = 0x0123; return m_tmsi; } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index bd4865d03..2b07eab24 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -117,37 +117,101 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA bool s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRANSPORT_STRUCT *ul_xport, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) { - - bool ue_valid = true; + uint8_t pd, msg_type, sec_hdr_type; uint32_t enb_ue_s1ap_id = ul_xport->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID; uint32_t mme_ue_s1ap_id = ul_xport->MME_UE_S1AP_ID.MME_UE_S1AP_ID; + ue_emm_ctx_t *ue_emm_ctx = NULL; + bool mac_valid = false; + //Get UE ECM context ue_ecm_ctx_t *ue_ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); if(ue_ecm_ctx == NULL) { m_s1ap_log->warning("Received uplink NAS, but could not find UE ECM context. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); return false; } - m_s1ap_log->debug("Received uplink NAS and found UE. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); - //Get NAS message type - uint8_t pd, msg_type; - srslte::byte_buffer_t *nas_msg = m_pool->allocate(); + m_s1ap_log->debug("Received uplink NAS and found UE ECM context. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); + //Parse NAS message header + srslte::byte_buffer_t *nas_msg = m_pool->allocate(); memcpy(nas_msg->msg, &ul_xport->NAS_PDU.buffer, ul_xport->NAS_PDU.n_octets); nas_msg->N_bytes = ul_xport->NAS_PDU.n_octets; liblte_mme_parse_msg_header((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &pd, &msg_type); - switch (msg_type) { + // Parse the message security header + liblte_mme_parse_msg_sec_header((LIBLTE_BYTE_MSG_STRUCT*)nas_msg, &pd, &sec_hdr_type); + + //Find UE EMM context if message is security protected. + if(sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS) + { + //Get EMM context to do integrity check/de-chiphering + ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); + if(ue_emm_ctx == NULL) + { + m_s1ap_log->warning("Uplink NAS: could not find security context for integrity protected message. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); + m_pool->deallocate(nas_msg); + return false; + } + } + + if(sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS) + { + //Plain NAS, only identity response is valid. + switch(msg_type) + { + case LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE: + m_s1ap_log->info("Uplink NAS: Received Identity Response\n"); + m_s1ap_log->console("Uplink NAS: Received Identity Response\n"); + handle_identity_response(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); + break; case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE: m_s1ap_log->info("Uplink NAS: Received Authentication Response\n"); m_s1ap_log->console("Uplink NAS: Received Authentication Response\n"); handle_nas_authentication_response(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); break; - case LIBLTE_MME_MSG_TYPE_SECURITY_MODE_COMPLETE: + default: + m_s1ap_log->warning("Unhandled Plain NAS message 0x%x\n", msg_type ); + m_s1ap_log->console("Unhandled Plain NAS message 0x%x\n", msg_type ); + m_pool->deallocate(nas_msg); + return false; + } + } + else if(sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_WITH_NEW_EPS_SECURITY_CONTEXT || sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED_WITH_NEW_EPS_SECURITY_CONTEXT) + { + switch (msg_type) { + case LIBLTE_MME_MSG_TYPE_SECURITY_MODE_COMPLETE: m_s1ap_log->info("Uplink NAS: Received Security Mode Complete\n"); m_s1ap_log->console("Uplink NAS: Received Security Mode Complete\n"); - handle_nas_security_mode_complete(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); + ue_emm_ctx->security_ctxt.ul_nas_count = 0; + ue_emm_ctx->security_ctxt.dl_nas_count = 0; + mac_valid = integrity_check(ue_emm_ctx,nas_msg); + if(mac_valid){ + handle_nas_security_mode_complete(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); + } else { + m_s1ap_log->warning("Invalid MAC in Security Mode Command Complete message.\n" ); + } + break; + default: + m_s1ap_log->warning("Unhandled NAS message with new EPS security context 0x%x\n", msg_type ); + m_s1ap_log->warning("Unhandled NAS message with new EPS security context 0x%x\n", msg_type ); + } + } + else if(sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY || sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED) + { + //Integrity protected NAS message, possibly chiphered. + ue_emm_ctx->security_ctxt.ul_nas_count++; + mac_valid = integrity_check(ue_emm_ctx,nas_msg); + if(!mac_valid && msg_type != LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE){ + m_s1ap_log->warning("Invalid MAC in NAS message type 0x%x.\n", msg_type); + m_pool->deallocate(nas_msg); + return false; + } + switch (msg_type) { + case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE: + m_s1ap_log->info("Uplink NAS: Received Authentication Response\n"); + m_s1ap_log->console("Uplink NAS: Received Authentication Response\n"); + handle_nas_authentication_response(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); break; case LIBLTE_MME_MSG_TYPE_ATTACH_COMPLETE: m_s1ap_log->info("Uplink NAS: Received Attach Complete\n"); @@ -159,11 +223,6 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA m_s1ap_log->console("Uplink NAS: Received ESM Information Response\n"); handle_esm_information_response(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); break; - case LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE: - m_s1ap_log->info("Uplink NAS: Received Identity Response\n"); - m_s1ap_log->console("Uplink NAS: Received Identity Response\n"); - handle_identity_response(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); - break; case LIBLTE_MME_MSG_TYPE_TRACKING_AREA_UPDATE_REQUEST: m_s1ap_log->info("UL NAS: Tracking Area Update Request\n"); handle_tracking_area_update_request(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); @@ -173,8 +232,16 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA m_s1ap_log->console("Unhandled NAS message 0x%x\n", msg_type ); m_pool->deallocate(nas_msg); return false; + } + } + else + { + m_s1ap_log->error("Unhandled security header type in Uplink NAS Transport: %d\n", sec_hdr_type); + m_pool->deallocate(nas_msg); + return false; } + if(*reply_flag == true) { m_s1ap_log->info("DL NAS: Sent Downlink NAS message\n"); @@ -221,11 +288,11 @@ s1ap_nas_transport::handle_nas_attach_request(uint32_t enb_ue_s1ap_id, { m_s1ap_log->console("Attach Request -- IMSI-style attach request\n"); m_s1ap_log->info("Attach Request -- IMSI-style attach request\n"); - if(sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS) + /*if(sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS) { m_s1ap_log->error("Attach request -- IMSI-stlye attach request is not plain NAS\n"); return false; - } + }*/ handle_nas_imsi_attach_request(enb_ue_s1ap_id, attach_req, pdn_con_req, reply_buffer, reply_flag, enb_sri); } else if(attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_GUTI) @@ -548,8 +615,6 @@ s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas return false; } - //TODO Check integrity - //TODO Handle imeisv if(sm_comp.imeisv_present) { @@ -858,7 +923,7 @@ s1ap_nas_transport::pack_authentication_reject(srslte::byte_buffer_t *reply_msg, if(err != LIBLTE_SUCCESS) { m_s1ap_log->error("Error packing Athentication Reject\n"); - m_s1ap_log->console("Error packing Athentication Reject\n"); + m_s1ap_log->console("Error packing Athentication Reject\n"); return false; } From 28d5130320137cc4fa6a5aa2b26aea08ae223285 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 13 Feb 2018 18:29:21 +0000 Subject: [PATCH 033/143] Incrementing DL NAS count --- srsepc/src/mme/s1ap_nas_transport.cc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 2b07eab24..1e71a5936 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -176,6 +176,15 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA m_pool->deallocate(nas_msg); return false; } + //Increment UL NAS count. + ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); + if(ue_emm_ctx == NULL) + { + m_s1ap_log->warning("Could not find UE EMM context in ", msg_type ); + m_pool->deallocate(nas_msg); + return false; + } + ue_emm_ctx->security_ctxt.ul_nas_count++; } else if(sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_WITH_NEW_EPS_SECURITY_CONTEXT || sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED_WITH_NEW_EPS_SECURITY_CONTEXT) { @@ -244,8 +253,12 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA if(*reply_flag == true) { - m_s1ap_log->info("DL NAS: Sent Downlink NAS message\n"); - m_s1ap_log->console("DL NAS: Sent Downlink NAs Message\n"); + if(ue_emm_ctx != NULL) + { + ue_emm_ctx->security_ctxt.dl_nas_count++; + m_s1ap_log->console("DL NAS: Sent Downlink NAs Message. DL NAS Count=%d\n",ue_emm_ctx->security_ctxt.dl_nas_count); + m_s1ap_log->info("DL NAS: Sent Downlink NAS message. DL NAS Count=%d\n",ue_emm_ctx->security_ctxt.dl_nas_count); + } } m_pool->deallocate(nas_msg); @@ -734,9 +747,9 @@ s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ //Get UE EMM context ue_emm_ctx_t ue_emm_ctx; if(m_s1ap->get_tmp_ue_emm_ctx(ue_ecm_ctx->mme_ue_s1ap_id, &ue_emm_ctx) == false) - { - m_s1ap_log->error("Could not find UE's temporary EMM context. MME UE S1AP Id: %d\n",ue_ecm_ctx->mme_ue_s1ap_id); - return false; + { + m_s1ap_log->error("Could not find UE's temporary EMM context. MME UE S1AP Id: %d\n",ue_ecm_ctx->mme_ue_s1ap_id); + return false; } ue_emm_ctx.imsi=imsi; From fa86862e8a65fd9d7e76c876159c988866ac870d Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 13 Feb 2018 19:40:13 +0000 Subject: [PATCH 034/143] Incrementing DL NAS COUNT and UL NAS COUNT. k_eNB is being generated incorrectly. --- srsepc/src/mme/s1ap_nas_transport.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 1e71a5936..580e66f60 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -255,9 +255,9 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA { if(ue_emm_ctx != NULL) { - ue_emm_ctx->security_ctxt.dl_nas_count++; m_s1ap_log->console("DL NAS: Sent Downlink NAs Message. DL NAS Count=%d\n",ue_emm_ctx->security_ctxt.dl_nas_count); m_s1ap_log->info("DL NAS: Sent Downlink NAS message. DL NAS Count=%d\n",ue_emm_ctx->security_ctxt.dl_nas_count); + //ue_emm_ctx->security_ctxt.dl_nas_count++; } } m_pool->deallocate(nas_msg); @@ -1034,7 +1034,7 @@ s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, uint8_t sec_hdr_type=3; - ue_emm_ctx->security_ctxt.dl_nas_count = 0; + // ue_emm_ctx->security_ctxt.dl_nas_count = 0; LIBLTE_ERROR_ENUM err = liblte_mme_pack_security_mode_command_msg(&sm_cmd,sec_hdr_type, ue_emm_ctx->security_ctxt.dl_nas_count,(LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); if(err != LIBLTE_SUCCESS) { From aedcfbb686340144b437684c9c8e7337407d13f2 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 14 Feb 2018 10:48:44 +0000 Subject: [PATCH 035/143] Added print of UL NAS Count --- srsepc/src/mme/s1ap_nas_transport.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 580e66f60..eaf01bd84 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -255,8 +255,8 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA { if(ue_emm_ctx != NULL) { - m_s1ap_log->console("DL NAS: Sent Downlink NAs Message. DL NAS Count=%d\n",ue_emm_ctx->security_ctxt.dl_nas_count); - m_s1ap_log->info("DL NAS: Sent Downlink NAS message. DL NAS Count=%d\n",ue_emm_ctx->security_ctxt.dl_nas_count); + m_s1ap_log->console("DL NAS: Sent Downlink NAs Message. DL NAS Count=%d, UL NAS count=%d\n",ue_emm_ctx->security_ctxt.dl_nas_count,ue_emm_ctx->security_ctxt.ul_nas_count ); + m_s1ap_log->info("DL NAS: Sent Downlink NAS message. DL NAS Count=%d, UL NAS count=%d\n",ue_emm_ctx->security_ctxt.dl_nas_count, ue_emm_ctx->security_ctxt.ul_nas_count); //ue_emm_ctx->security_ctxt.dl_nas_count++; } } From 012f026543e59730fbb323bdda7cef38942478c3 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 14 Feb 2018 10:59:54 +0000 Subject: [PATCH 036/143] Added print of UL NAS count and DL NAS count in nas_transport. --- srsepc/src/mme/s1ap_nas_transport.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 083201ff6..952d94efe 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -199,8 +199,11 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA if(*reply_flag == true) { - m_s1ap_log->info("DL NAS: Sent Downlink NAS message\n"); - m_s1ap_log->console("DL NAS: Sent Downlink NAs Message\n"); + if(ue_ctx != NULL) + { + m_s1ap_log->console("DL NAS: Sent Downlink NAs Message. DL NAS Count=%d, UL NAS Count=%d\n",ue_ctx->security_ctxt.dl_nas_count, ue_ctx->security_ctxt.ul_nas_count); + m_s1ap_log->info("DL NAS: Sent Downlink NAS message. DL NAS Count=%d, UL NAS Count=%d\n",ue_ctx->security_ctxt.dl_nas_count, ue_ctx->security_ctxt.ul_nas_count); + } } m_pool->deallocate(nas_msg); From 1c4dce80660bbd1b048500b4669d2243945c5791 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 14 Feb 2018 12:28:55 +0000 Subject: [PATCH 037/143] Generating k_enb in the securty mode command. Fixed wrong k_enb generation. Integrity is being checked corretly in upstream NAS messages. --- srsepc/hdr/mme/s1ap_common.h | 1 + srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 7 +++---- srsepc/src/mme/s1ap_nas_transport.cc | 17 +++++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index 84ced0637..8bb6944ff 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -115,6 +115,7 @@ typedef struct{ srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo; uint8_t k_nas_enc[32]; uint8_t k_nas_int[32]; + uint8_t k_enb[32]; LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT ue_network_cap; bool ms_network_cap_present; LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT ms_network_cap; diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 3fce06de6..b2654cedd 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -167,10 +167,9 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, } // in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer[0] = 1; //EIA1 } - uint8_t key_enb[32]; - liblte_security_generate_k_enb(ue_emm_ctx->security_ctxt.k_asme, ue_emm_ctx->security_ctxt.ul_nas_count, key_enb); - liblte_unpack(key_enb, 32, in_ctxt_req->SecurityKey.buffer); - m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",ue_emm_ctx->security_ctxt.ul_nas_count); + //Get K eNB + liblte_unpack(ue_emm_ctx->security_ctxt.k_enb, 32, in_ctxt_req->SecurityKey.buffer); + m_s1ap_log->info_hex(ue_emm_ctx->security_ctxt.k_enb, 32, "Initial Context Setup Request -- Key eNB\n"); //Set Attach accepted and activat default bearer NAS messages if(cs_resp->paa_present != true) { diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index eaf01bd84..60f6c9402 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -27,6 +27,7 @@ #include "mme/s1ap.h" #include "mme/s1ap_nas_transport.h" #include "srslte/common/security.h" +#include "srslte/common/liblte_security.h" namespace srsepc{ @@ -1042,17 +1043,25 @@ s1ap_nas_transport::pack_security_mode_command(srslte::byte_buffer_t *reply_msg, return false; } - //Generate MAC for integrity protection - //FIXME Write wrapper to support EIA1, EIA2, etc. + //Generate EPS security context uint8_t mac[4]; - srslte::security_generate_k_nas( ue_emm_ctx->security_ctxt.k_asme, srslte::CIPHERING_ALGORITHM_ID_EEA0, srslte::INTEGRITY_ALGORITHM_ID_128_EIA1, ue_emm_ctx->security_ctxt.k_nas_enc, ue_emm_ctx->security_ctxt.k_nas_int ); - + srslte::security_generate_k_nas( ue_emm_ctx->security_ctxt.k_asme, + srslte::CIPHERING_ALGORITHM_ID_EEA0, + srslte::INTEGRITY_ALGORITHM_ID_128_EIA1, + ue_emm_ctx->security_ctxt.k_nas_enc, + ue_emm_ctx->security_ctxt.k_nas_int + ); + uint8_t key_enb[32]; + liblte_security_generate_k_enb(ue_emm_ctx->security_ctxt.k_asme, ue_emm_ctx->security_ctxt.ul_nas_count, ue_emm_ctx->security_ctxt.k_enb); + m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",ue_emm_ctx->security_ctxt.ul_nas_count); + //Generate MAC for integrity protection + //FIXME Write wrapper to support EIA1, EIA2, etc. srslte::security_128_eia1 (&ue_emm_ctx->security_ctxt.k_nas_int[16], ue_emm_ctx->security_ctxt.dl_nas_count, 0, From 7ae2975de44132c1e76813e74700aa9048a8ee94 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 14 Feb 2018 17:40:05 +0000 Subject: [PATCH 038/143] Starting to get M-TMSI from service request. --- srsepc/hdr/mme/s1ap_nas_transport.h | 6 ++ srsepc/src/mme/s1ap_nas_transport.cc | 99 +++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 2 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index 8d9b7429a..c36081ae2 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -65,6 +65,11 @@ public: srslte::byte_buffer_t *reply_buffer, bool* reply_flag, struct sctp_sndrcvinfo *enb_sri); + bool handle_nas_service_request(uint32_t m_tmsi, + srslte::byte_buffer_t *nas_msg, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri); bool handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag); bool handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); @@ -73,6 +78,7 @@ public: bool handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); bool integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu); + bool short_integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu); bool pack_authentication_request(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t next_mme_ue_s1ap_id, uint8_t *autn,uint8_t *rand); bool pack_authentication_reject(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 60f6c9402..3377dd755 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -80,7 +80,7 @@ bool s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *init_ue, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) { - LIBLTE_MME_SERVICE_REQUEST_MSG_STRUCT service_req; + //LIBLTE_MME_SERVICE_REQUEST_MSG_STRUCT service_req; m_s1ap_log->console("Received Initial UE Message.\n"); m_s1ap_log->info("Received Initial UE Message.\n"); @@ -107,7 +107,26 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA { m_s1ap_log->info("Received Service Request \n"); m_s1ap_log->console("Received Service Request \n"); - liblte_mme_unpack_service_request_msg((LIBLTE_BYTE_MSG_STRUCT*) nas_msg, &service_req); + if(!init_ue->S_TMSI_present) + { + m_s1ap_log->error("Service request -- S-TMSI not present\n "); + m_s1ap_log->console("Service request -- S-TMSI not present\n" ); + } + /* + typedef struct{ + bool ext; + LIBLTE_S1AP_MME_CODE_STRUCT mMEC; + LIBLTE_S1AP_M_TMSI_STRUCT m_TMSI; + LIBLTE_S1AP_PROTOCOLEXTENSIONCONTAINER_STRUCT iE_Extensions; + bool iE_Extensions_present; + }LIBLTE_S1AP_S_TMSI_STRUCT; + typedef struct{ + uint8_t buffer[4]; + }LIBLTE_S1AP_M_TMSI_STRUCT;*/ + uint32_t *m_tmsi = (uint32_t*) &init_ue->S_TMSI.m_TMSI.buffer; + m_s1ap_log->info("Service request -- S-TMSI 0x%x\n ", *m_tmsi); + m_s1ap_log->console("Service request -- S-TMSI 0x%x\n", *m_tmsi ); + handle_nas_service_request(*m_tmsi, nas_msg, reply_buffer,reply_flag, enb_sri); return false; } m_pool->deallocate(nas_msg); @@ -544,6 +563,52 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, return true; } +bool +s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, + srslte::byte_buffer_t *nas_msg, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri) +{ + + bool mac_valid = false; + LIBLTE_MME_SERVICE_REQUEST_MSG_STRUCT service_req; + + LIBLTE_ERROR_ENUM err = liblte_mme_unpack_service_request_msg((LIBLTE_BYTE_MSG_STRUCT*) nas_msg, &service_req); + if(err !=LIBLTE_SUCCESS) + { + m_s1ap_log->error("Could not unpack service request\n"); + return false; + } + + std::map::iterator it = m_s1ap->m_tmsi_to_imsi.find(m_tmsi); + if(it == m_s1ap->m_tmsi_to_imsi.end()) + { + m_s1ap_log->console("Could not find IMSI from M-TMSI\n"); + m_s1ap_log->error("Could not find IMSI from M-TMSI\n"); + //FIXME send service reject + return false; + } + + ue_emm_ctx_t *ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(it->second); + if(ue_emm_ctx == NULL) + { + m_s1ap_log->console("Could not find UE security context\n"); + m_s1ap_log->error("Could not find UE security context\n"); + //FIXME send service reject + return false; + } + mac_valid = short_integrity_check(ue_emm_ctx,nas_msg); + if(mac_valid) + m_s1ap_log->console("Banzai!!!\n"); + /* + typedef struct{ + LIBLTE_MME_KSI_AND_SEQUENCE_NUMBER_STRUCT ksi_and_seq_num; + uint16 short_mac; + }LIBLTE_MME_SERVICE_REQUEST_MSG_STRUCT; + */ + return true; +} bool s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag) { @@ -818,6 +883,36 @@ s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *n return true; } +bool +s1ap_nas_transport::short_integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu) +{ + uint8_t exp_mac[2]; + uint8_t *mac = &pdu->msg[2]; + int i; + + srslte::security_128_eia1(&emm_ctx->security_ctxt.k_nas_int[16], + emm_ctx->security_ctxt.ul_nas_count, + 0, + SECURITY_DIRECTION_UPLINK, + &pdu->msg[0], + 2, + &exp_mac[0]); + + // Check if expected mac equals the sent mac + for(i=0; i<2; i++){ + if(exp_mac[i] != mac[i]){ + m_s1ap_log->warning("Short integrity check failure. Local: count=%d, [%02x %02x], " + "Received: count=%d, [%02x %02x]\n", + emm_ctx->security_ctxt.ul_nas_count, exp_mac[0], exp_mac[1], + pdu->msg[1] & 0x1F, mac[0], mac[1]); + return false; + } + } + m_s1ap_log->info("Integrity check ok. Local: count=%d, Received: count=%d\n", + emm_ctx->security_ctxt.ul_nas_count, pdu->msg[1] & 0x1F); + return true; +} + bool s1ap_nas_transport::integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu) From f4fba4e2f5062d2e0075546649636d9b2d9f13df Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 15 Feb 2018 11:58:46 +0000 Subject: [PATCH 039/143] Fixed ntohl bug in getting the service request m-tmsi. --- srsepc/src/mme/s1ap.cc | 2 +- srsepc/src/mme/s1ap_nas_transport.cc | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 31db87cf5..f72eb9bc4 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -517,7 +517,7 @@ s1ap::allocate_m_tmsi(uint64_t imsi) { uint32_t m_tmsi = m_next_m_tmsi++; m_tmsi_to_imsi.insert(std::pair(m_tmsi,imsi)); - m_s1ap_log->info("Allocated M-TMSI 0x%x,\n",m_tmsi); + m_s1ap_log->debug("Allocated M-TMSI 0x%x to IMSI %015ul,\n",m_tmsi,imsi); //uint32_t m_tmsi = 0x0123; return m_tmsi; } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 3377dd755..a40461064 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -124,9 +124,9 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA uint8_t buffer[4]; }LIBLTE_S1AP_M_TMSI_STRUCT;*/ uint32_t *m_tmsi = (uint32_t*) &init_ue->S_TMSI.m_TMSI.buffer; - m_s1ap_log->info("Service request -- S-TMSI 0x%x\n ", *m_tmsi); - m_s1ap_log->console("Service request -- S-TMSI 0x%x\n", *m_tmsi ); - handle_nas_service_request(*m_tmsi, nas_msg, reply_buffer,reply_flag, enb_sri); + m_s1ap_log->info("Service request -- S-TMSI 0x%x\n ", ntohl(*m_tmsi)); + m_s1ap_log->console("Service request -- S-TMSI 0x%x\n", ntohl(*m_tmsi) ); + handle_nas_service_request(ntohl(*m_tmsi), nas_msg, reply_buffer,reply_flag, enb_sri); return false; } m_pool->deallocate(nas_msg); @@ -584,8 +584,8 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, std::map::iterator it = m_s1ap->m_tmsi_to_imsi.find(m_tmsi); if(it == m_s1ap->m_tmsi_to_imsi.end()) { - m_s1ap_log->console("Could not find IMSI from M-TMSI\n"); - m_s1ap_log->error("Could not find IMSI from M-TMSI\n"); + m_s1ap_log->console("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + m_s1ap_log->error("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); //FIXME send service reject return false; } From 094a7d272f56f4e325b58190865ac8b522c81797 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 15 Feb 2018 13:53:21 +0000 Subject: [PATCH 040/143] Fixed bug in short integrity check. Service request integrity check works now. --- srsepc/src/mme/s1ap_nas_transport.cc | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index a40461064..73891846d 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -112,17 +112,6 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA m_s1ap_log->error("Service request -- S-TMSI not present\n "); m_s1ap_log->console("Service request -- S-TMSI not present\n" ); } - /* - typedef struct{ - bool ext; - LIBLTE_S1AP_MME_CODE_STRUCT mMEC; - LIBLTE_S1AP_M_TMSI_STRUCT m_TMSI; - LIBLTE_S1AP_PROTOCOLEXTENSIONCONTAINER_STRUCT iE_Extensions; - bool iE_Extensions_present; - }LIBLTE_S1AP_S_TMSI_STRUCT; - typedef struct{ - uint8_t buffer[4]; - }LIBLTE_S1AP_M_TMSI_STRUCT;*/ uint32_t *m_tmsi = (uint32_t*) &init_ue->S_TMSI.m_TMSI.buffer; m_s1ap_log->info("Service request -- S-TMSI 0x%x\n ", ntohl(*m_tmsi)); m_s1ap_log->console("Service request -- S-TMSI 0x%x\n", ntohl(*m_tmsi) ); @@ -598,6 +587,7 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, //FIXME send service reject return false; } + ue_emm_ctx->security_ctxt.ul_nas_count++; mac_valid = short_integrity_check(ue_emm_ctx,nas_msg); if(mac_valid) m_s1ap_log->console("Banzai!!!\n"); @@ -886,7 +876,7 @@ s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *n bool s1ap_nas_transport::short_integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu) { - uint8_t exp_mac[2]; + uint8_t exp_mac[4]; uint8_t *mac = &pdu->msg[2]; int i; @@ -900,10 +890,10 @@ s1ap_nas_transport::short_integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_bu // Check if expected mac equals the sent mac for(i=0; i<2; i++){ - if(exp_mac[i] != mac[i]){ - m_s1ap_log->warning("Short integrity check failure. Local: count=%d, [%02x %02x], " + if(exp_mac[i+2] != mac[i]){ + m_s1ap_log->warning("Short integrity check failure. Local: count=%d, [%02x %02x %02x %02x], " "Received: count=%d, [%02x %02x]\n", - emm_ctx->security_ctxt.ul_nas_count, exp_mac[0], exp_mac[1], + emm_ctx->security_ctxt.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; } From 2e90ce370b16470a0d089a6b6e9349daffc35914 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 15 Feb 2018 18:30:43 +0000 Subject: [PATCH 041/143] Starting to prepare MME UE context release request. --- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 30 +++++- srsepc/src/mme/s1ap_nas_transport.cc | 132 ++++++++++++++++++++++++-- 2 files changed, 153 insertions(+), 9 deletions(-) diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index b2654cedd..bfbcc4978 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -264,9 +264,11 @@ s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_I } bool -s1ap_ctx_mngmt_proc::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT *ue_rel, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) +s1ap_ctx_mngmt_proc::handle_ue_context_release_request(uint32_t mme_ue_s1ap_id, srslte::byte_buffer_t *reply_buffer) { + LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT ue_rel_req; + uint32_t mme_ue_s1ap_id = ue_rel->MME_UE_S1AP_ID.MME_UE_S1AP_ID; m_s1ap_log->info("Received UE Context Release Request. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); m_s1ap_log->console("Received UE Context Release Request. MME-UE S1AP Id %d\n", mme_ue_s1ap_id); @@ -306,4 +308,30 @@ s1ap_ctx_mngmt_proc::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECON return true; } +bool +s1ap_ctx_mngmt_proc::pack_ue_context_release_request(uint32_t mme_ue_s1ap_id, srslte::byte_buffer_t *reply_buffer) +{ + + //Prepare reply PDU + LIBLTE_S1AP_S1AP_PDU_STRUCT pdu; + bzero(&pdu, sizeof(LIBLTE_S1AP_S1AP_PDU_STRUCT)); + pdu.choice_type = LIBLTE_S1AP_S1AP_PDU_CHOICE_INITIATINGMESSAGE; + + LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *init = &pdu.choice.initiatingMessage; + init->procedureCode = LIBLTE_S1AP_PROC_ID_UECONTEXTRELEASEREQUEST; + init->choice_type = LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_INITIALCONTEXTRELEASEREQUEST; + + LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT *ctx_rel_req = &init->choice.UEContextReleaseRequest; + + LIBLTE_ERROR_ENUM err = liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)reply_buffer); + if(err != LIBLTE_SUCCESS) + { + m_s1ap_log->error("Could not pack Initial Context Setup Request Message\n"); + return false; + } + + return true; +} + + } //namespace srsepc diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 73891846d..3089e18c9 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -590,13 +590,26 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, ue_emm_ctx->security_ctxt.ul_nas_count++; mac_valid = short_integrity_check(ue_emm_ctx,nas_msg); if(mac_valid) - m_s1ap_log->console("Banzai!!!\n"); - /* - typedef struct{ - LIBLTE_MME_KSI_AND_SEQUENCE_NUMBER_STRUCT ksi_and_seq_num; - uint16 short_mac; - }LIBLTE_MME_SERVICE_REQUEST_MSG_STRUCT; - */ + { + m_s1ap_log->console("Service Request -- Short MAC valid\n"); + m_s1ap_log->info("Service Request -- Short MAC valid\n"); + ue_ecm_ctx_t ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(ue_emm_ctx.mme_ue_s1ap_id); + if(ecm_ctx !=NULL) + { + //Service request to Connected UE. + //Delete ECM context and connect. + m_mme_gtpc->send_delete_session_request(ue_ecm_ctx); + pack_context_release_request(); + } + else + { + //UE not connect. Connect normally. + } + else + { + m_s1ap_log->console("Service Request -- Short MAC invalid. Re-starting authentication procedure \n"); + m_s1ap_log->console("Service Request -- Short MAC invalid. Re-starting authentication procedure \n"); + } return true; } bool @@ -866,7 +879,110 @@ s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *n m_s1ap_log->console("Tracking area accept to MME-UE S1AP Id %d\n", ue_ecm_ctx->mme_ue_s1ap_id); LIBLTE_MME_TRACKING_AREA_UPDATE_ACCEPT_MSG_STRUCT tau_acc; - + + + bool t3412_present; + bool guti_present; + bool tai_list_present; + bool eps_bearer_context_status_present; + bool lai_present; + bool ms_id_present; + bool emm_cause_present; + bool t3402_present; + bool t3423_present; + bool equivalent_plmns_present; + bool emerg_num_list_present; + bool eps_network_feature_support_present; + bool additional_update_result_present; + bool t3412_ext_present; + + //Get decimal MCC and MNC + uint32_t mcc = 0; + mcc += 0x000F & m_s1ap->m_s1ap_args.mcc; + mcc += 10*( (0x00F0 & m_s1ap->m_s1ap_args.mcc) >> 4); + mcc += 100*( (0x0F00 & m_s1ap->m_s1ap_args.mcc) >> 8); + + uint32_t mnc = 0; + if( 0xFF00 == (m_s1ap->m_s1ap_args.mnc & 0xFF00 )) + { + //Two digit MNC + mnc += 0x000F & m_s1ap->m_s1ap_args.mnc; + mnc += 10*((0x00F0 & m_s1ap->m_s1ap_args.mnc) >> 4); + } + else + { + //Three digit MNC + mnc += 0x000F & m_s1ap->m_s1ap_args.mnc; + mnc += 10*((0x00F0 & m_s1ap->m_s1ap_args.mnc) >> 4); + mnc += 100*((0x0F00 & m_s1ap->m_s1ap_args.mnc) >> 8); + } + + //T3412 Timer + tau_acc.t3412_present = true; + tau_acc.t3412.unit = LIBLTE_MME_GPRS_TIMER_UNIT_1_MINUTE; // GPRS 1 minute unit + tau_acc.t3412.value = 30; // 30 minute periodic timer + + //GUTI + tau_acc.guti_present=true; + tau_acc.guti.type_of_id = 6; //110 -> GUTI + tau_acc.guti.guti.mcc = mcc; + tau_acc.guti.guti.mnc = mnc; + tau_acc.guti.guti.mme_group_id = m_s1ap->m_s1ap_args.mme_group; + tau_acc.guti.guti.mme_code = m_s1ap->m_s1ap_args.mme_code; + tau_acc.guti.guti.m_tmsi = 0xF000; + m_s1ap_log->debug("Allocated GUTI: MCC %d, MNC %d, MME Group Id %d, MME Code 0x%x, M-TMSI 0x%x\n", + tau_acc.guti.guti.mcc, + tau_acc.guti.guti.mnc, + tau_acc.guti.guti.mme_group_id, + tau_acc.guti.guti.mme_code, + tau_acc.guti.guti.m_tmsi); + + //Unused Options + tau_acc.t3402_present = false; + tau_acc.t3423_present = false; + tau_acc.equivalent_plmns_present = false; + tau_acc.emerg_num_list_present = false; + tau_acc.eps_network_feature_support_present = false; + tau_acc.additional_update_result_present = false; + tau_acc.t3412_ext_present = false; + + + //eps_update_result = LIBLTE_MME_TR + /* +typedef struct{ + LIBLTE_MME_GPRS_TIMER_STRUCT t3412; + LIBLTE_MME_EPS_MOBILE_ID_STRUCT guti; + LIBLTE_MME_TRACKING_AREA_IDENTITY_LIST_STRUCT tai_list; + LIBLTE_MME_EPS_BEARER_CONTEXT_STATUS_STRUCT eps_bearer_context_status; + LIBLTE_MME_LOCATION_AREA_ID_STRUCT lai; + LIBLTE_MME_MOBILE_ID_STRUCT ms_id; + LIBLTE_MME_GPRS_TIMER_STRUCT t3402; + LIBLTE_MME_GPRS_TIMER_STRUCT t3423; + LIBLTE_MME_PLMN_LIST_STRUCT equivalent_plmns; + LIBLTE_MME_EMERGENCY_NUMBER_LIST_STRUCT emerg_num_list; + LIBLTE_MME_EPS_NETWORK_FEATURE_SUPPORT_STRUCT eps_network_feature_support; + LIBLTE_MME_GPRS_TIMER_3_STRUCT t3412_ext; + LIBLTE_MME_ADDITIONAL_UPDATE_RESULT_ENUM additional_update_result; + uint8 eps_update_result; + uint8 emm_cause; + bool t3412_present; + bool guti_present; + bool tai_list_present; + bool eps_bearer_context_status_present; + bool lai_present; + bool ms_id_present; + bool emm_cause_present; + bool t3402_present; + bool t3423_present; + bool equivalent_plmns_present; + bool emerg_num_list_present; + bool eps_network_feature_support_present; + bool additional_update_result_present; + bool t3412_ext_present;v +}LIBLTE_MME_TRACKING_AREA_UPDATE_ACCEPT_MSG_STRUCT; + */ + + //Send reply to eNB //*reply_flag = true; From 24d394d8ca66869178ee2e611f5e238ca13f655f Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 15 Feb 2018 18:47:56 +0000 Subject: [PATCH 042/143] Fixed some compilation issues. --- srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h | 1 + srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 16 +++++++++++++--- srsepc/src/mme/s1ap_nas_transport.cc | 7 ++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h index 2eaca64ab..2e448f110 100644 --- a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h @@ -50,6 +50,7 @@ public: bool send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, struct srslte::gtpc_create_session_response *cs_resp, struct srslte::gtpc_f_teid_ie sgw_ctrl_fteid); bool handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT *in_ctxt_resp); bool handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT *ue_rel, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); + bool pack_ue_context_release_request(uint32_t mme_ue_s1ap_id, srslte::byte_buffer_t *reply_buffer); private: s1ap_ctx_mngmt_proc(); diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index bfbcc4978..527f310b5 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -264,7 +264,7 @@ s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_I } bool -s1ap_ctx_mngmt_proc::handle_ue_context_release_request(uint32_t mme_ue_s1ap_id, srslte::byte_buffer_t *reply_buffer) +s1ap_ctx_mngmt_proc::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT *ue_rel, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) { LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT ue_rel_req; @@ -319,10 +319,20 @@ s1ap_ctx_mngmt_proc::pack_ue_context_release_request(uint32_t mme_ue_s1ap_id, sr LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *init = &pdu.choice.initiatingMessage; init->procedureCode = LIBLTE_S1AP_PROC_ID_UECONTEXTRELEASEREQUEST; - init->choice_type = LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_INITIALCONTEXTRELEASEREQUEST; + init->choice_type = LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_UECONTEXTRELEASEREQUEST; LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT *ctx_rel_req = &init->choice.UEContextReleaseRequest; - + + /* + typedef struct{ + bool ext; + LIBLTE_S1AP_MME_UE_S1AP_ID_STRUCT MME_UE_S1AP_ID; + LIBLTE_S1AP_ENB_UE_S1AP_ID_STRUCT eNB_UE_S1AP_ID; + LIBLTE_S1AP_CAUSE_STRUCT Cause; + LIBLTE_S1AP_GWCONTEXTRELEASEINDICATION_ENUM_EXT GWContextReleaseIndication; + bool GWContextReleaseIndication_present; + }LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT; + */ LIBLTE_ERROR_ENUM err = liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)reply_buffer); if(err != LIBLTE_SUCCESS) { diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 3089e18c9..af7d785cb 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -593,18 +593,19 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, { m_s1ap_log->console("Service Request -- Short MAC valid\n"); m_s1ap_log->info("Service Request -- Short MAC valid\n"); - ue_ecm_ctx_t ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(ue_emm_ctx.mme_ue_s1ap_id); + ue_ecm_ctx_t *ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(ue_emm_ctx->mme_ue_s1ap_id); if(ecm_ctx !=NULL) { //Service request to Connected UE. //Delete ECM context and connect. - m_mme_gtpc->send_delete_session_request(ue_ecm_ctx); - pack_context_release_request(); + m_mme_gtpc->send_delete_session_request(ecm_ctx); + //pack_context_release_request(); } else { //UE not connect. Connect normally. } + } else { m_s1ap_log->console("Service Request -- Short MAC invalid. Re-starting authentication procedure \n"); From 2cb1f27ddb812a111a3e6e582afe7524ee9ccf4a Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 16 Feb 2018 17:47:55 +0000 Subject: [PATCH 043/143] Adding UE context release command. Fixing issue when identity response is integrity protected. --- srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h | 2 +- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 38 ++++++++++++++++----------- srsepc/src/mme/s1ap_mngmt_proc.cc | 6 +++-- srsepc/src/mme/s1ap_nas_transport.cc | 30 ++++++++++++++------- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h index 2e448f110..9979b6594 100644 --- a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h @@ -50,7 +50,7 @@ public: bool send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, struct srslte::gtpc_create_session_response *cs_resp, struct srslte::gtpc_f_teid_ie sgw_ctrl_fteid); bool handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT *in_ctxt_resp); bool handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT *ue_rel, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); - bool pack_ue_context_release_request(uint32_t mme_ue_s1ap_id, srslte::byte_buffer_t *reply_buffer); + bool send_ue_context_release_command(ue_ecm_ctx_t *ecm_ctx, srslte::byte_buffer_t *reply_buffer); private: s1ap_ctx_mngmt_proc(); diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 527f310b5..ba9d38577 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -309,36 +309,44 @@ s1ap_ctx_mngmt_proc::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECON } bool -s1ap_ctx_mngmt_proc::pack_ue_context_release_request(uint32_t mme_ue_s1ap_id, srslte::byte_buffer_t *reply_buffer) +s1ap_ctx_mngmt_proc::send_ue_context_release_command(ue_ecm_ctx_t *ecm_ctx, srslte::byte_buffer_t *reply_buffer) { + int s1mme = m_s1ap->get_s1_mme(); + //Prepare reply PDU LIBLTE_S1AP_S1AP_PDU_STRUCT pdu; bzero(&pdu, sizeof(LIBLTE_S1AP_S1AP_PDU_STRUCT)); pdu.choice_type = LIBLTE_S1AP_S1AP_PDU_CHOICE_INITIATINGMESSAGE; LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *init = &pdu.choice.initiatingMessage; - init->procedureCode = LIBLTE_S1AP_PROC_ID_UECONTEXTRELEASEREQUEST; - init->choice_type = LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_UECONTEXTRELEASEREQUEST; + init->procedureCode = LIBLTE_S1AP_PROC_ID_UECONTEXTRELEASE; + init->choice_type = LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_UECONTEXTRELEASECOMMAND; + + LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASECOMMAND_STRUCT *ctx_rel_cmd = &init->choice.UEContextReleaseCommand; + + ctx_rel_cmd->UE_S1AP_IDs.choice_type = LIBLTE_S1AP_UE_S1AP_IDS_CHOICE_UE_S1AP_ID_PAIR; + ctx_rel_cmd->UE_S1AP_IDs.choice.uE_S1AP_ID_pair.mME_UE_S1AP_ID.MME_UE_S1AP_ID = ecm_ctx->mme_ue_s1ap_id; + ctx_rel_cmd->UE_S1AP_IDs.choice.uE_S1AP_ID_pair.eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ecm_ctx->enb_ue_s1ap_id; + + ctx_rel_cmd->Cause.choice_type = LIBLTE_S1AP_CAUSE_CHOICE_NAS; + ctx_rel_cmd->Cause.choice.nas.ext = false; + ctx_rel_cmd->Cause.choice.nas.e = LIBLTE_S1AP_CAUSENAS_NORMAL_RELEASE; - LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT *ctx_rel_req = &init->choice.UEContextReleaseRequest; - - /* - typedef struct{ - bool ext; - LIBLTE_S1AP_MME_UE_S1AP_ID_STRUCT MME_UE_S1AP_ID; - LIBLTE_S1AP_ENB_UE_S1AP_ID_STRUCT eNB_UE_S1AP_ID; - LIBLTE_S1AP_CAUSE_STRUCT Cause; - LIBLTE_S1AP_GWCONTEXTRELEASEINDICATION_ENUM_EXT GWContextReleaseIndication; - bool GWContextReleaseIndication_present; - }LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT; - */ LIBLTE_ERROR_ENUM err = liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)reply_buffer); if(err != LIBLTE_SUCCESS) { m_s1ap_log->error("Could not pack Initial Context Setup Request Message\n"); return false; } + //Send Reply to eNB + int n_sent = sctp_send(s1mme,reply_buffer->msg, reply_buffer->N_bytes, &ecm_ctx->enb_sri, 0); + if(n_sent == -1) + { + m_s1ap_log->error("Failed to send Initial Context Setup Request\n"); + return false; + } + return true; } diff --git a/srsepc/src/mme/s1ap_mngmt_proc.cc b/srsepc/src/mme/s1ap_mngmt_proc.cc index 8fa469ec3..43fa5d860 100644 --- a/srsepc/src/mme/s1ap_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_mngmt_proc.cc @@ -234,7 +234,7 @@ s1ap_mngmt_proc::pack_s1_setup_response(s1ap_args_t s1ap_args, srslte::byte_buff LIBLTE_S1AP_SERVEDGUMMEISITEM_STRUCT *serv_gummei = &s1_resp->ServedGUMMEIs.buffer[0]; serv_gummei->ext=false; - //serv_gummei->iE_Extensions=false; + serv_gummei->iE_Extensions_present = false; uint32_t plmn=0; srslte::s1ap_mccmnc_to_plmn(s1ap_args.mcc, s1ap_args.mnc, &plmn); @@ -257,7 +257,9 @@ s1ap_mngmt_proc::pack_s1_setup_response(s1ap_args_t s1ap_args, srslte::byte_buff //Relay Unsupported s1_resp->MMERelaySupportIndicator_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 af7d785cb..8dd6c6e68 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -158,15 +158,27 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); if(ue_emm_ctx == NULL) { - m_s1ap_log->warning("Uplink NAS: could not find security context for integrity protected message. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); - m_pool->deallocate(nas_msg); - return false; + //No EMM context found. + //Perhaps a temporary context is being created? + //This can happen with integrity protected identity reponse and authentication response messages + if( !(msg_type == LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE && sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY) && + !(msg_type == LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE && sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY)) + { + m_s1ap_log->warning("Uplink NAS: could not find security context for integrity protected message. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); + m_pool->deallocate(nas_msg); + return false; + } } } - if(sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS) + if( sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS || + (msg_type == LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE && sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY) || + (msg_type == LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE && sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY)) { - //Plain NAS, only identity response is valid. + //Only identity response and authentication response are valid as plain NAS. + //Sometimes authentication response and identity are sent as integrity protected, + //but these messages are sent when the securty context is not setup yet, so we cannot integrity check it. + //FIXME Double-check switch(msg_type) { case LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE: @@ -220,17 +232,17 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA //Integrity protected NAS message, possibly chiphered. ue_emm_ctx->security_ctxt.ul_nas_count++; mac_valid = integrity_check(ue_emm_ctx,nas_msg); - if(!mac_valid && msg_type != LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE){ + if(!mac_valid){ m_s1ap_log->warning("Invalid MAC in NAS message type 0x%x.\n", msg_type); m_pool->deallocate(nas_msg); return false; } switch (msg_type) { - case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE: + /*case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE: m_s1ap_log->info("Uplink NAS: Received Authentication Response\n"); m_s1ap_log->console("Uplink NAS: Received Authentication Response\n"); handle_nas_authentication_response(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); - break; + break;*/ case LIBLTE_MME_MSG_TYPE_ATTACH_COMPLETE: m_s1ap_log->info("Uplink NAS: Received Attach Complete\n"); m_s1ap_log->console("Uplink NAS: Received Attach Complete\n"); @@ -599,7 +611,7 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, //Service request to Connected UE. //Delete ECM context and connect. m_mme_gtpc->send_delete_session_request(ecm_ctx); - //pack_context_release_request(); + //m_s1ap send_context_release_request(ecm_ctx, reply_buffer); } else { From 82b3e5e380e538b4ce73a1bc0a161799019c6fab Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 16 Feb 2018 19:08:04 +0000 Subject: [PATCH 044/143] Integrity protection of GUTI attach OK. Attach complete not yet sent. --- srsepc/src/mme/s1ap.cc | 2 +- srsepc/src/mme/s1ap_nas_transport.cc | 55 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index f72eb9bc4..ef335d533 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -517,7 +517,7 @@ s1ap::allocate_m_tmsi(uint64_t imsi) { uint32_t m_tmsi = m_next_m_tmsi++; m_tmsi_to_imsi.insert(std::pair(m_tmsi,imsi)); - m_s1ap_log->debug("Allocated M-TMSI 0x%x to IMSI %015ul,\n",m_tmsi,imsi); + m_s1ap_log->debug("Allocated M-TMSI 0x%x to IMSI %015lu,\n",m_tmsi,imsi); //uint32_t m_tmsi = 0x0123; return m_tmsi; } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 8dd6c6e68..9c445878f 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -80,11 +80,6 @@ bool s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *init_ue, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) { - //LIBLTE_MME_SERVICE_REQUEST_MSG_STRUCT service_req; - - m_s1ap_log->console("Received Initial UE Message.\n"); - m_s1ap_log->info("Received Initial UE Message.\n"); - //Get info from initial UE message uint32_t enb_ue_s1ap_id = init_ue->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID; @@ -101,6 +96,8 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA liblte_mme_parse_msg_header((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &pd, &msg_type); if(msg_type == LIBLTE_MME_MSG_TYPE_ATTACH_REQUEST) { + m_s1ap_log->info("Received Attach Request \n"); + m_s1ap_log->console("Received Attach Request \n"); handle_nas_attach_request(enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); } else if(msg_type == LIBLTE_MME_SECURITY_HDR_TYPE_SERVICE_REQUEST) @@ -118,6 +115,11 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA handle_nas_service_request(ntohl(*m_tmsi), nas_msg, reply_buffer,reply_flag, enb_sri); return false; } + else + { + m_s1ap_log->info("Unhandled Initial UE Message 0x%x\n",msg_type); + m_s1ap_log->console("Unhandled Initial UE Message 0x%x \n", msg_type); + } m_pool->deallocate(nas_msg); return true; @@ -238,11 +240,6 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA return false; } switch (msg_type) { - /*case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE: - m_s1ap_log->info("Uplink NAS: Received Authentication Response\n"); - m_s1ap_log->console("Uplink NAS: Received Authentication Response\n"); - handle_nas_authentication_response(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); - break;*/ case LIBLTE_MME_MSG_TYPE_ATTACH_COMPLETE: m_s1ap_log->info("Uplink NAS: Received Attach Complete\n"); m_s1ap_log->console("Uplink NAS: Received Attach Complete\n"); @@ -258,8 +255,8 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA handle_tracking_area_update_request(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); break; default: - m_s1ap_log->warning("Unhandled NAS message 0x%x\n", msg_type ); - m_s1ap_log->console("Unhandled NAS message 0x%x\n", msg_type ); + m_s1ap_log->warning("Unhandled NAS integrity protected message 0x%x\n", msg_type ); + m_s1ap_log->console("Unhandled NAS integrity protected message 0x%x\n", msg_type ); m_pool->deallocate(nas_msg); return false; } @@ -311,33 +308,17 @@ s1ap_nas_transport::handle_nas_attach_request(uint32_t enb_ue_s1ap_id, return false; } - //Parse the message security header - uint8 pd = 0; - uint8 msg_type = 0; - uint8 sec_hdr_type = 0; - liblte_mme_parse_msg_sec_header((LIBLTE_BYTE_MSG_STRUCT*)nas_msg, &pd, &sec_hdr_type); - //Get attach type from attach request if(attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMSI) { m_s1ap_log->console("Attach Request -- IMSI-style attach request\n"); m_s1ap_log->info("Attach Request -- IMSI-style attach request\n"); - /*if(sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS) - { - m_s1ap_log->error("Attach request -- IMSI-stlye attach request is not plain NAS\n"); - return false; - }*/ handle_nas_imsi_attach_request(enb_ue_s1ap_id, attach_req, pdn_con_req, reply_buffer, reply_flag, enb_sri); } else if(attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_GUTI) { m_s1ap_log->console("Attach Request -- GUTI-style attach request\n"); m_s1ap_log->info("Attach Request -- GUTI-style attach request\n"); - if(sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY) - { - m_s1ap_log->error("Attach request -- GUTI-stlye attach request is not integrity protected\n"); - return false; - } handle_nas_guti_attach_request(enb_ue_s1ap_id, attach_req, pdn_con_req, nas_msg, reply_buffer, reply_flag, enb_sri); } else @@ -462,6 +443,23 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, bool* reply_flag, struct sctp_sndrcvinfo *enb_sri) { + //Parse the message security header + uint8 pd = 0; + uint8 sec_hdr_type = 0; + liblte_mme_parse_msg_sec_header((LIBLTE_BYTE_MSG_STRUCT*)nas_msg, &pd, &sec_hdr_type); + + bool integrity_valid = false; + if(sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY) + { + m_s1ap_log->info("Attach request -- GUTI-stlye attach request is not integrity protected\n"); + m_s1ap_log->console("Attach request -- GUTI-stlye attach request is not integrity protected\n"); + } + else{ + m_s1ap_log->info("Attach request -- GUTI-stlye attach request is integrity protected\n"); + m_s1ap_log->console("Attach request -- GUTI-stlye attach request is integrity protected\n"); + } + + //GUTI style attach uint32_t m_tmsi = attach_req.eps_mobile_id.guti.m_tmsi; std::map::iterator it = m_s1ap->m_tmsi_to_imsi.find(m_tmsi); @@ -541,6 +539,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, m_s1ap_log->console("Found UE context. IMSI: %015lu\n",ue_emm_ctx->imsi); //Check NAS integrity bool msg_valid = false; + ue_emm_ctx->security_ctxt.ul_nas_count++; msg_valid = integrity_check(ue_emm_ctx,nas_msg); if(msg_valid == true) { From 4ee08fdecaafb33a65dedfbda440003e99a04a64 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 19 Feb 2018 15:19:07 +0000 Subject: [PATCH 045/143] Changing send initial context setup request to not need the create session response struct. --- srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h | 4 +- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 84 ++++++++++++--------------- srsepc/src/mme/s1ap_nas_transport.cc | 30 ++++++++-- 3 files changed, 67 insertions(+), 51 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h index 9979b6594..3e4136141 100644 --- a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h @@ -47,7 +47,9 @@ public: void init(void); - bool send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, struct srslte::gtpc_create_session_response *cs_resp, struct srslte::gtpc_f_teid_ie sgw_ctrl_fteid); + //bool send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, struct srslte::gtpc_create_session_response *cs_resp, struct srslte::gtpc_f_teid_ie sgw_ctrl_fteid); + bool send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, ue_ecm_ctx_t *ecm_ctx, uint16_t erab_id, + struct srslte::gtpc_f_teid_ie sgw_ctrl_fteid, struct srslte::gtpc_f_teid_ie sgw_s1u_fteid, struct srslte::gtpc_pdn_address_allocation_ie pdn_addr_aloc); bool handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT *in_ctxt_resp); bool handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT *ue_rel, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool send_ue_context_release_command(ue_ecm_ctx_t *ecm_ctx, srslte::byte_buffer_t *reply_buffer); diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index ba9d38577..6d645c095 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -77,7 +77,12 @@ s1ap_ctx_mngmt_proc::init(void) } bool -s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, struct srslte::gtpc_create_session_response *cs_resp, struct srslte::gtpc_f_teid_ie sgw_ctrl_fteid) +s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, + ue_ecm_ctx_t *ecm_ctx, + uint16_t erab_id, + struct srslte::gtpc_f_teid_ie sgw_ctrl_fteid, + struct srslte::gtpc_f_teid_ie sgw_s1u_fteid, + struct srslte::gtpc_pdn_address_allocation_ie pdn_addr_alloc) { int s1mme = m_s1ap->get_s1_mme(); @@ -97,23 +102,9 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, m_s1ap_log->info("Preparing to send Initial Context Setup request\n"); - //Find UE Context - ue_ecm_ctx_t *ue_ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); - if(ue_ecm_ctx == NULL) - { - m_s1ap_log->error("Could not find UE to send Setup Context Request. MME S1AP Id: %d", mme_ue_s1ap_id); - return false; - } - ue_emm_ctx_t *ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); - if(ue_emm_ctx == NULL) - { - m_s1ap_log->error("Could not find UE to send Setup Context Request. MME S1AP Id: %d", mme_ue_s1ap_id); - return false; - } - //Add MME and eNB S1AP Ids - in_ctxt_req->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ecm_ctx->mme_ue_s1ap_id; - in_ctxt_req->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ecm_ctx->enb_ue_s1ap_id; + in_ctxt_req->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ecm_ctx->mme_ue_s1ap_id; + in_ctxt_req->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ecm_ctx->enb_ue_s1ap_id; //Set UE-AMBR in_ctxt_req->uEaggregateMaximumBitrate.uEaggregateMaximumBitRateDL.BitRate=1000000000; @@ -121,7 +112,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, //Setup eRAB context in_ctxt_req->E_RABToBeSetupListCtxtSUReq.len = 1; - erab_ctxt->e_RAB_ID.E_RAB_ID = cs_resp->eps_bearer_context_created.ebi; + erab_ctxt->e_RAB_ID.E_RAB_ID = erab_id; //Setup E-RAB QoS parameters erab_ctxt->e_RABlevelQoSParameters.qCI.QCI = 9; erab_ctxt->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel.PriorityLevel = 15 ;//Lowest @@ -131,25 +122,25 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, erab_ctxt->e_RABlevelQoSParameters.gbrQosInformation_present=false; //Set E-RAB S-GW F-TEID - if (cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid_present == false){ - m_s1ap_log->error("Did not receive S1-U TEID in create session response\n"); - return false; - } + //if (cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid_present == false){ + // m_s1ap_log->error("Did not receive S1-U TEID in create session response\n"); + // return false; + //} erab_ctxt->transportLayerAddress.n_bits = 32; //IPv4 - uint32_t sgw_s1u_ip = htonl(cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.ipv4); + uint32_t sgw_s1u_ip = htonl(sgw_s1u_fteid.ipv4); //uint32_t sgw_s1u_ip = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.ipv4; uint8_t *tmp_ptr = erab_ctxt->transportLayerAddress.buffer; liblte_value_2_bits(sgw_s1u_ip, &tmp_ptr, 32);//FIXME consider ipv6 - uint32_t tmp_teid = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.teid; - memcpy(erab_ctxt->gTP_TEID.buffer, &tmp_teid, sizeof(uint32_t)); + uint32_t sgw_s1u_teid = sgw_s1u_fteid.teid; + memcpy(erab_ctxt->gTP_TEID.buffer, &sgw_s1u_teid, sizeof(uint32_t)); //Set UE security capabilities and k_enb bzero(in_ctxt_req->UESecurityCapabilities.encryptionAlgorithms.buffer,sizeof(uint8_t)*16); bzero(in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer,sizeof(uint8_t)*16); for(int i = 0; i<3; i++) { - if(ue_emm_ctx->security_ctxt.ue_network_cap.eea[i+1] == true) + if(emm_ctx->security_ctxt.ue_network_cap.eea[i+1] == true) { in_ctxt_req->UESecurityCapabilities.encryptionAlgorithms.buffer[i] = 1; //EEA supported } @@ -157,7 +148,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, { in_ctxt_req->UESecurityCapabilities.encryptionAlgorithms.buffer[i] = 0; //EEA not supported } - if(ue_emm_ctx->security_ctxt.ue_network_cap.eia[i+1] == true) + if(emm_ctx->security_ctxt.ue_network_cap.eia[i+1] == true) { in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer[i] = 1; //EEA supported } @@ -168,21 +159,22 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, // in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer[0] = 1; //EIA1 } //Get K eNB - liblte_unpack(ue_emm_ctx->security_ctxt.k_enb, 32, in_ctxt_req->SecurityKey.buffer); - m_s1ap_log->info_hex(ue_emm_ctx->security_ctxt.k_enb, 32, "Initial Context Setup Request -- Key eNB\n"); + liblte_unpack(emm_ctx->security_ctxt.k_enb, 32, in_ctxt_req->SecurityKey.buffer); + m_s1ap_log->info_hex(emm_ctx->security_ctxt.k_enb, 32, "Initial Context Setup Request -- Key eNB\n"); + //Set Attach accepted and activat default bearer NAS messages - if(cs_resp->paa_present != true) - { - m_s1ap_log->error("PAA not present\n"); - return false; - } - if(cs_resp->paa.pdn_type != srslte::GTPC_PDN_TYPE_IPV4) - { - m_s1ap_log->error("IPv6 not supported yet\n"); - return false; - } + //if(cs_resp->paa_present != true) + //{ + // m_s1ap_log->error("PDN Adress Allocation not present\n"); + // return false; + //} + //if(cs_resp->paa.pdn_type != srslte::GTPC_PDN_TYPE_IPV4) + //{ + // m_s1ap_log->error("IPv6 not supported yet\n"); + // return false; + //} srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); - m_s1ap_nas_transport->pack_attach_accept(ue_emm_ctx, ue_ecm_ctx, erab_ctxt, &cs_resp->paa, nas_buffer); + m_s1ap_nas_transport->pack_attach_accept(emm_ctx, ecm_ctx, erab_ctxt, &pdn_addr_alloc, nas_buffer); LIBLTE_ERROR_ENUM err = liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)reply_buffer); @@ -192,7 +184,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, return false; } //Send Reply to eNB - ssize_t n_sent = sctp_send(s1mme,reply_buffer->msg, reply_buffer->N_bytes, &ue_ecm_ctx->enb_sri, 0); + ssize_t n_sent = sctp_send(s1mme,reply_buffer->msg, reply_buffer->N_bytes, &ecm_ctx->enb_sri, 0); if(n_sent == -1) { m_s1ap_log->error("Failed to send Initial Context Setup Request\n"); @@ -200,16 +192,16 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, } //Change E-RAB state to Context Setup Requested and save S-GW control F-TEID - ue_ecm_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].state = ERAB_CTX_REQUESTED; - ue_ecm_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.teid = sgw_ctrl_fteid.teid; - ue_ecm_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.ipv4 = sgw_ctrl_fteid.ipv4; + ecm_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].state = ERAB_CTX_REQUESTED; + ecm_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.teid = sgw_ctrl_fteid.teid; + ecm_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.ipv4 = sgw_ctrl_fteid.ipv4; struct in_addr addr; addr.s_addr = htonl(sgw_s1u_ip); m_s1ap_log->info("Sent Intial Context Setup Request. E-RAB id %d \n",erab_ctxt->e_RAB_ID.E_RAB_ID); - m_s1ap_log->info("Initial Context -- S1-U TEID 0x%x. IP %s \n", tmp_teid,inet_ntoa(addr)); + m_s1ap_log->info("Initial Context -- S1-U TEID 0x%x. IP %s \n", sgw_s1u_teid,inet_ntoa(addr)); m_s1ap_log->console("Sent Intial Context Setup Request, E-RAB id %d\n",erab_ctxt->e_RAB_ID.E_RAB_ID); - m_s1ap_log->console("Initial Context -- S1-U TEID 0x%x. IP %s \n", tmp_teid,inet_ntoa(addr)); + m_s1ap_log->console("Initial Context -- S1-U TEID 0x%x. IP %s \n", sgw_s1u_teid,inet_ntoa(addr)); m_pool->deallocate(reply_buffer); m_pool->deallocate(nas_buffer); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 9c445878f..99cbc52f5 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -378,7 +378,6 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, //Save whether secure ESM information transfer is necessary ue_ecm_ctx.eit = pdn_con_req.esm_info_transfer_flag_present; - //Add eNB info to UE ctxt //Initialize E-RABs for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) { @@ -543,6 +542,28 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, msg_valid = integrity_check(ue_emm_ctx,nas_msg); if(msg_valid == true) { + //Create new MME UE S1AP Identity + ue_emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + + //Create UE ECM context + ue_ecm_ctx_t ue_ecm_ctx; + + //Set UE ECM context + ue_ecm_ctx.imsi = ue_emm_ctx->imsi; + ue_ecm_ctx.mme_ue_s1ap_id = ue_emm_ctx->mme_ue_s1ap_id; + //Set eNB information + ue_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; + memcpy(&ue_ecm_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + //Save whether secure ESM information transfer is necessary + ue_ecm_ctx.eit = pdn_con_req.esm_info_transfer_flag_present; + + //Initialize E-RABs + for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) + { + ue_ecm_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED; + ue_ecm_ctx.erabs_ctx[i].erab_id = i; + } + m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); //Create session request m_s1ap_log->console("GUTI Attach -- NAS Integrity OK."); m_mme_gtpc->send_create_session_request(ue_emm_ctx->imsi, ue_emm_ctx->mme_ue_s1ap_id); @@ -608,9 +629,10 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, if(ecm_ctx !=NULL) { //Service request to Connected UE. - //Delete ECM context and connect. - m_mme_gtpc->send_delete_session_request(ecm_ctx); - //m_s1ap send_context_release_request(ecm_ctx, reply_buffer); + //Delete eNB context and connect. + + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(ecm_ctx); } else { From fc0f1e4c23407546dbff1af46dfe8abda8890b22 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 19 Feb 2018 17:54:01 +0000 Subject: [PATCH 046/143] Sendind intial context setup in response to service request. --- srsepc/hdr/mme/s1ap_common.h | 2 + srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h | 3 +- srsepc/src/mme/mme_gtpc.cc | 42 ++++++++++++++++++++- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 53 ++++++++++----------------- srsepc/src/mme/s1ap_nas_transport.cc | 8 +++- 5 files changed, 69 insertions(+), 39 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index 8bb6944ff..c69eb05d1 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -126,6 +126,8 @@ typedef struct{ uint8_t erab_id; srslte::gtpc_f_teid_ie enb_fteid; srslte::gtpc_f_teid_ie sgw_ctrl_fteid; + srslte::gtpc_f_teid_ie sgw_s1u_fteid; + srslte::gtpc_pdn_address_allocation_ie pdn_addr_alloc; } erab_ctx_t; typedef struct{ diff --git a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h index 3e4136141..44458aea6 100644 --- a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h @@ -48,8 +48,7 @@ public: void init(void); //bool send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, struct srslte::gtpc_create_session_response *cs_resp, struct srslte::gtpc_f_teid_ie sgw_ctrl_fteid); - bool send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, ue_ecm_ctx_t *ecm_ctx, uint16_t erab_id, - struct srslte::gtpc_f_teid_ie sgw_ctrl_fteid, struct srslte::gtpc_f_teid_ie sgw_s1u_fteid, struct srslte::gtpc_pdn_address_allocation_ie pdn_addr_aloc); + bool send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, ue_ecm_ctx_t *ecm_ctx, erab_ctx_t *erab_ctx); bool handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT *in_ctxt_resp); bool handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT *ue_rel, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool send_ue_context_release_command(ue_ecm_ctx_t *ecm_ctx, srslte::byte_buffer_t *reply_buffer); diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 6f4a1cdcc..e6f4511df 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -162,11 +162,51 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu) sgw_ctrl_fteid.teid = cs_resp_pdu->header.teid; sgw_ctrl_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 + if (cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid_present == false){ + m_mme_gtpc_log->error("Did not receive SGW S1-U F-TEID in create session response\n"); + return; + } m_mme_gtpc_log->console("Create Session Response -- SPGW control TEID %d\n", sgw_ctrl_fteid.teid); in_addr s1u_addr; s1u_addr.s_addr = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.ipv4; m_mme_gtpc_log->console("Create Session Response -- SPGW S1-U Address: %s\n", inet_ntoa(s1u_addr)); - m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(mme_s1ap_id, cs_resp, sgw_ctrl_fteid); + + //Check UE Ipv4 address was allocated + if(cs_resp->paa_present != true) + { + m_mme_gtpc_log->error("PDN Adress Allocation not present\n"); + return; + } + if(cs_resp->paa.pdn_type != srslte::GTPC_PDN_TYPE_IPV4) + { + m_mme_gtpc_log->error("IPv6 not supported yet\n"); + return; + } + + //Save create session response info to E-RAB context + ue_ecm_ctx_t *ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_s1ap_id); + if(ecm_ctx ==NULL) + { + m_mme_gtpc_log->error("Could not find UE ECM context\n"); + return; + } + ue_emm_ctx_t *emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ecm_ctx->imsi); + if(emm_ctx ==NULL) + { + m_mme_gtpc_log->error("Could not find UE EMM context\n"); + return; + } + + //Set EPS bearer context + //FIXME default EPS bearer is hard-coded + int default_bearer=5; + erab_ctx_t *erab_ctx = &ecm_ctx->erabs_ctx[default_bearer]; + erab_ctx->pdn_addr_alloc= cs_resp->paa; + erab_ctx->sgw_ctrl_fteid = sgw_ctrl_fteid; + erab_ctx->sgw_s1u_fteid = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid; + + m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, erab_ctx); } diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 6d645c095..c68301ff0 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -79,10 +79,7 @@ s1ap_ctx_mngmt_proc::init(void) bool s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, ue_ecm_ctx_t *ecm_ctx, - uint16_t erab_id, - struct srslte::gtpc_f_teid_ie sgw_ctrl_fteid, - struct srslte::gtpc_f_teid_ie sgw_s1u_fteid, - struct srslte::gtpc_pdn_address_allocation_ie pdn_addr_alloc) + erab_ctx_t *erab_ctx) { int s1mme = m_s1ap->get_s1_mme(); @@ -97,7 +94,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPREQUEST_STRUCT *in_ctxt_req = &init->choice.InitialContextSetupRequest; - LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctxt = &in_ctxt_req->E_RABToBeSetupListCtxtSUReq.buffer[0]; //FIXME support more than one erab + LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctx_req = &in_ctxt_req->E_RABToBeSetupListCtxtSUReq.buffer[0]; //FIXME support more than one erab srslte::byte_buffer_t *reply_buffer = m_pool->allocate(); m_s1ap_log->info("Preparing to send Initial Context Setup request\n"); @@ -112,28 +109,28 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, //Setup eRAB context in_ctxt_req->E_RABToBeSetupListCtxtSUReq.len = 1; - erab_ctxt->e_RAB_ID.E_RAB_ID = erab_id; + erab_ctx_req->e_RAB_ID.E_RAB_ID = erab_ctx->erab_id; //Setup E-RAB QoS parameters - erab_ctxt->e_RABlevelQoSParameters.qCI.QCI = 9; - erab_ctxt->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel.PriorityLevel = 15 ;//Lowest - erab_ctxt->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability = LIBLTE_S1AP_PRE_EMPTIONCAPABILITY_SHALL_NOT_TRIGGER_PRE_EMPTION; - erab_ctxt->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability = LIBLTE_S1AP_PRE_EMPTIONVULNERABILITY_PRE_EMPTABLE; + erab_ctx_req->e_RABlevelQoSParameters.qCI.QCI = 9; + erab_ctx_req->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel.PriorityLevel = 15 ;//Lowest + erab_ctx_req->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability = LIBLTE_S1AP_PRE_EMPTIONCAPABILITY_SHALL_NOT_TRIGGER_PRE_EMPTION; + erab_ctx_req->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability = LIBLTE_S1AP_PRE_EMPTIONVULNERABILITY_PRE_EMPTABLE; - erab_ctxt->e_RABlevelQoSParameters.gbrQosInformation_present=false; + erab_ctx_req->e_RABlevelQoSParameters.gbrQosInformation_present=false; //Set E-RAB S-GW F-TEID //if (cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid_present == false){ // m_s1ap_log->error("Did not receive S1-U TEID in create session response\n"); // return false; //} - erab_ctxt->transportLayerAddress.n_bits = 32; //IPv4 - uint32_t sgw_s1u_ip = htonl(sgw_s1u_fteid.ipv4); + erab_ctx_req->transportLayerAddress.n_bits = 32; //IPv4 + uint32_t sgw_s1u_ip = htonl(erab_ctx->sgw_s1u_fteid.ipv4); //uint32_t sgw_s1u_ip = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.ipv4; - uint8_t *tmp_ptr = erab_ctxt->transportLayerAddress.buffer; + uint8_t *tmp_ptr = erab_ctx_req->transportLayerAddress.buffer; liblte_value_2_bits(sgw_s1u_ip, &tmp_ptr, 32);//FIXME consider ipv6 - uint32_t sgw_s1u_teid = sgw_s1u_fteid.teid; - memcpy(erab_ctxt->gTP_TEID.buffer, &sgw_s1u_teid, sizeof(uint32_t)); + uint32_t sgw_s1u_teid = erab_ctx->sgw_s1u_fteid.teid; + memcpy(erab_ctx_req->gTP_TEID.buffer, &sgw_s1u_teid, sizeof(uint32_t)); //Set UE security capabilities and k_enb bzero(in_ctxt_req->UESecurityCapabilities.encryptionAlgorithms.buffer,sizeof(uint8_t)*16); @@ -156,25 +153,13 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, { in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer[i] = 0; //EEA not supported } - // in_ctxt_req->UESecurityCapabilities.integrityProtectionAlgorithms.buffer[0] = 1; //EIA1 } //Get K eNB liblte_unpack(emm_ctx->security_ctxt.k_enb, 32, in_ctxt_req->SecurityKey.buffer); m_s1ap_log->info_hex(emm_ctx->security_ctxt.k_enb, 32, "Initial Context Setup Request -- Key eNB\n"); - //Set Attach accepted and activat default bearer NAS messages - //if(cs_resp->paa_present != true) - //{ - // m_s1ap_log->error("PDN Adress Allocation not present\n"); - // return false; - //} - //if(cs_resp->paa.pdn_type != srslte::GTPC_PDN_TYPE_IPV4) - //{ - // m_s1ap_log->error("IPv6 not supported yet\n"); - // return false; - //} srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); - m_s1ap_nas_transport->pack_attach_accept(emm_ctx, ecm_ctx, erab_ctxt, &pdn_addr_alloc, nas_buffer); + m_s1ap_nas_transport->pack_attach_accept(emm_ctx, ecm_ctx, erab_ctx_req, &erab_ctx->pdn_addr_alloc, nas_buffer); LIBLTE_ERROR_ENUM err = liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)reply_buffer); @@ -192,15 +177,15 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, } //Change E-RAB state to Context Setup Requested and save S-GW control F-TEID - ecm_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].state = ERAB_CTX_REQUESTED; - ecm_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.teid = sgw_ctrl_fteid.teid; - ecm_ctx->erabs_ctx[erab_ctxt->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.ipv4 = sgw_ctrl_fteid.ipv4; + ecm_ctx->erabs_ctx[erab_ctx_req->e_RAB_ID.E_RAB_ID].state = ERAB_CTX_REQUESTED; + //ecm_ctx->erabs_ctx[erab_ctx_req->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.teid = sgw_ctrl_fteid.teid; + //ecm_ctx->erabs_ctx[erab_ctx_req->e_RAB_ID.E_RAB_ID].sgw_ctrl_fteid.ipv4 = sgw_ctrl_fteid.ipv4; struct in_addr addr; addr.s_addr = htonl(sgw_s1u_ip); - m_s1ap_log->info("Sent Intial Context Setup Request. E-RAB id %d \n",erab_ctxt->e_RAB_ID.E_RAB_ID); + m_s1ap_log->info("Sent Intial 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("Sent Intial Context Setup Request, E-RAB id %d\n",erab_ctxt->e_RAB_ID.E_RAB_ID); + m_s1ap_log->console("Sent Intial Context Setup Request, E-RAB id %d\n",erab_ctx_req->e_RAB_ID.E_RAB_ID); m_s1ap_log->console("Initial Context -- S1-U TEID 0x%x. IP %s \n", sgw_s1u_teid,inet_ntoa(addr)); m_pool->deallocate(reply_buffer); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 99cbc52f5..acf30c422 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -630,13 +630,17 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, { //Service request to Connected UE. //Delete eNB context and connect. - + m_s1ap_log->console("Service Request -- User has ECM context already\n"); + m_s1ap_log->info("Service Request -- User has ECM context already\n"); m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); - m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(ecm_ctx); + int default_bearer_id = 5; + m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(ue_emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[default_bearer_id]); } else { //UE not connect. Connect normally. + m_s1ap_log->console("Service Request -- User without ECM context\n"); + m_s1ap_log->info("Service Request -- User without ECM context\n"); } } else From c02b67b709067a0e418fff095bcdf0a2fe0ef1a7 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 19 Feb 2018 19:28:54 +0000 Subject: [PATCH 047/143] Sending initial context setup request on receiving service request --- srsepc/hdr/mme/s1ap_nas_transport.h | 1 + srsepc/src/mme/s1ap_nas_transport.cc | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index c36081ae2..7cc692a4e 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -66,6 +66,7 @@ public: bool* reply_flag, struct sctp_sndrcvinfo *enb_sri); bool handle_nas_service_request(uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool* reply_flag, diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index acf30c422..3abc81768 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -110,9 +110,12 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA m_s1ap_log->console("Service request -- S-TMSI not present\n" ); } uint32_t *m_tmsi = (uint32_t*) &init_ue->S_TMSI.m_TMSI.buffer; + uint32_t enb_ue_s1ap_id = init_ue->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID; m_s1ap_log->info("Service request -- S-TMSI 0x%x\n ", ntohl(*m_tmsi)); m_s1ap_log->console("Service request -- S-TMSI 0x%x\n", ntohl(*m_tmsi) ); - handle_nas_service_request(ntohl(*m_tmsi), nas_msg, reply_buffer,reply_flag, enb_sri); + m_s1ap_log->info("Service request -- eNB UE S1AP Id %d\n ", enb_ue_s1ap_id); + m_s1ap_log->console("Service request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); + handle_nas_service_request(ntohl(*m_tmsi), enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); return false; } else @@ -586,6 +589,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, bool s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_buffer, bool* reply_flag, @@ -629,6 +633,11 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, if(ecm_ctx !=NULL) { //Service request to Connected UE. + //Set eNB UE S1ap identity + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + m_s1ap_log->console("Service Request -- eNB UE S1AP Id %d \n", enb_ue_s1ap_id); + m_s1ap_log->info("Service Request -- eNB UE S1AP Id %d\n ", enb_ue_s1ap_id); + //Delete eNB context and connect. m_s1ap_log->console("Service Request -- User has ECM context already\n"); m_s1ap_log->info("Service Request -- User has ECM context already\n"); From 5f4613bffdf141d172e44ea195dda9321ae77593 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 19 Feb 2018 20:09:09 +0000 Subject: [PATCH 048/143] Fixing conflicts from merge. --- srsepc/hdr/mme/s1ap_nas_transport.h | 2 ++ srsepc/src/mme/s1ap_nas_transport.cc | 29 ++++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index 59375dbcd..b8eb98805 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -79,6 +79,8 @@ public: bool handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); bool handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); + bool handle_authentication_failure(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); + bool integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu); bool short_integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 281364bf4..fa0da0d2c 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -259,8 +259,7 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA break; case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_FAILURE: m_s1ap_log->info("Uplink NAS: Authentication Failure\n"); - handle_authentication_failure(nas_msg, ue_ctx, reply_buffer, reply_flag); - ue_ctx->security_ctxt.ul_nas_count++; + handle_authentication_failure(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); break; default: m_s1ap_log->warning("Unhandled NAS integrity protected message 0x%x\n", msg_type ); @@ -929,10 +928,10 @@ s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *n dw_nas->HandoverRestrictionList_present=false; dw_nas->SubscriberProfileIDforRFP_present=false; //m_s1ap_log->console("Tracking area accept to MME-UE S1AP Id %d\n", ue_ctx->mme_ue_s1ap_id); - /* + LIBLTE_MME_TRACKING_AREA_UPDATE_ACCEPT_MSG_STRUCT tau_acc; - + /* bool t3412_present; bool guti_present; bool tai_list_present; @@ -1104,7 +1103,7 @@ s1ap_nas_transport::integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t bool -s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) +s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { uint8_t autn[16]; uint8_t rand[16]; @@ -1117,6 +1116,12 @@ s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg return false; } + ue_emm_ctx_t *emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); + if(emm_ctx == NULL) + { + m_s1ap_log->error("Could not find UE EMM context\n"); + return false; + } switch(auth_fail.emm_cause){ case 20: @@ -1134,22 +1139,22 @@ s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg m_s1ap_log->error("Missing fail parameter\n"); return false; } - if(!m_hss->resync_sqn(ue_ctx->imsi, auth_fail.auth_fail_param)) + if(!m_hss->resync_sqn(ue_ecm_ctx->imsi, auth_fail.auth_fail_param)) { - m_s1ap_log->console("Resynchronization failed. IMSI %015lu\n", ue_ctx->imsi); - m_s1ap_log->info("Resynchronization failed. IMSI %015lu\n", ue_ctx->imsi); + m_s1ap_log->console("Resynchronization failed. IMSI %015lu\n", ue_ecm_ctx->imsi); + m_s1ap_log->info("Resynchronization failed. IMSI %015lu\n", ue_ecm_ctx->imsi); return false; } //Get Authentication Vectors from HSS - if(!m_hss->gen_auth_info_answer(ue_ctx->imsi, ue_ctx->security_ctxt.k_asme, autn, rand, ue_ctx->security_ctxt.xres)) + if(!m_hss->gen_auth_info_answer(ue_ecm_ctx->imsi, emm_ctx->security_ctxt.k_asme, autn, rand, emm_ctx->security_ctxt.xres)) { - m_s1ap_log->console("User not found. IMSI %015lu\n", ue_ctx->imsi); - m_s1ap_log->info("User not found. IMSI %015lu\n", ue_ctx->imsi); + m_s1ap_log->console("User not found. IMSI %015lu\n", ue_ecm_ctx->imsi); + m_s1ap_log->info("User not found. IMSI %015lu\n", ue_ecm_ctx->imsi); return false; } //Pack NAS Authentication Request in Downlink NAS Transport msg - pack_authentication_request(reply_msg, ue_ctx->enb_ue_s1ap_id, ue_ctx->mme_ue_s1ap_id, autn, rand); + pack_authentication_request(reply_msg, ue_ecm_ctx->enb_ue_s1ap_id, ue_ecm_ctx->mme_ue_s1ap_id, autn, rand); //Send reply to eNB *reply_flag = true; From 0389338fe3c8ed0a30c430f7e47c0b3d46b8e5a5 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 19 Feb 2018 20:54:43 +0000 Subject: [PATCH 049/143] whitespace change --- srsepc/src/mme/s1ap_nas_transport.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index fa0da0d2c..96834c3ba 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -1163,7 +1163,7 @@ s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg //TODO Start T3460 Timer! break; - } + } return true; } From bdc72c65c451eec5763c34b10e9df2e5dfcd9f55 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 20 Feb 2018 18:54:41 +0000 Subject: [PATCH 050/143] Adding print to debug TPC issue. --- srsepc/hdr/spgw/spgw.h | 4 ++++ srsepc/src/spgw/spgw.cc | 23 +++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/srsepc/hdr/spgw/spgw.h b/srsepc/hdr/spgw/spgw.h index 095b4d9b0..f39674ba7 100644 --- a/srsepc/hdr/spgw/spgw.h +++ b/srsepc/hdr/spgw/spgw.h @@ -117,6 +117,10 @@ private: uint32_t m_h_next_ue_ip; + /*Time*/ + struct timeval m_t_last_dl; + struct timeval m_t_last_ul; + /*Logs*/ srslte::log_filter *m_spgw_log; diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index add16b2c4..55f19818d 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -224,6 +224,9 @@ spgw::init_sgi_if(spgw_args_t *args) return srslte::ERROR_CANT_START; } + //Set initial time of setup + gettimeofday(&m_t_last_dl, NULL); + m_sgi_up = true; return(srslte::ERROR_NONE); } @@ -297,15 +300,11 @@ spgw::run_thread() if (FD_ISSET(m_s1u, &set)) { msg->N_bytes = recvfrom(m_s1u, msg->msg, SRSLTE_MAX_BUFFER_SIZE_BYTES, 0, &src_addr, &addrlen ); - //m_spgw_log->console("Received PDU from S1-U. Bytes %d\n", msg->N_bytes); - //m_spgw_log->debug("Received PDU from S1-U. Bytes %d\n", msg->N_bytes); handle_s1u_pdu(msg); } if (FD_ISSET(m_sgi_if, &set)) { msg->N_bytes = read(sgi, msg->msg, SRSLTE_MAX_BUFFER_SIZE_BYTES); - //m_spgw_log->console("Received PDU from SGi. Bytes %d\n", msg->N_bytes); - //m_spgw_log->debug("Received PDU from SGi. Bytes %d\n", msg->N_bytes); handle_sgi_pdu(msg); } } @@ -328,6 +327,8 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg) bool ip_found = false; srslte::gtpc_f_teid_ie enb_fteid; + struct timeval t_now, t_delta; + version = msg->msg[0]>>4; ((uint8_t*)&dest_ip)[0] = msg->msg[16]; ((uint8_t*)&dest_ip)[1] = msg->msg[17]; @@ -380,8 +381,18 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg) m_spgw_log->error("Error sending packet to eNB\n"); return; } - //m_spgw_log->console("Sent packet to %s:%d. Bytes=%d/%d\n",inet_ntoa(enb_addr.sin_addr), GTPU_RX_PORT,n,msg->N_bytes); - + else if((unsigned int) n!=msg->N_bytes) + { + m_spgw_log->error("Mis-match between packet bytes and sent bytes: Sent: %d, Packet: %d \n",n,msg->N_bytes); + } + t_delta.tv_sec = t_now.tv_sec - m_t_last_dl.tv_sec; + t_delta.tv_usec = t_now.tv_sec - m_t_last_dl.tv_usec; + gettimeofday(&t_now, NULL); + if(t_delta.tv_sec>=5) + { + m_t_last_dl = t_now; + m_spgw_log->console("Sent %d bytes DL over the last %d.%d seconds. Bitrate = \n",msg->N_bytes, t_delta.tv_sec, t_delta.tv_usec/1000); + } return; } From a7b540c18e92e1b4ccf9c60fb923980cf57297b6 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 20 Feb 2018 18:55:13 +0000 Subject: [PATCH 051/143] Fixing bug in S1 Setup response. --- srsepc/src/main.cc | 1 + srsepc/src/mme/s1ap_mngmt_proc.cc | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index 89ae4c83e..3a931ddd2 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -204,6 +204,7 @@ parse_args(all_args_t *args, int argc, char* argv[]) { } args->mme_args.s1ap_args.mme_bind_addr = mme_bind_addr; + args->mme_args.s1ap_args.mme_name = mme_name; args->spgw_args.gtpu_bind_addr = spgw_bind_addr; args->spgw_args.sgi_if_addr = sgi_if_addr; args->hss_args.db_file = hss_db_file; diff --git a/srsepc/src/mme/s1ap_mngmt_proc.cc b/srsepc/src/mme/s1ap_mngmt_proc.cc index 43fa5d860..a4117d893 100644 --- a/srsepc/src/mme/s1ap_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_mngmt_proc.cc @@ -102,6 +102,7 @@ s1ap_mngmt_proc::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRU { //eNB already registered //TODO replace enb_ctx + m_s1ap_log->warning("eNB Already registered\n"); } else { @@ -218,11 +219,11 @@ s1ap_mngmt_proc::pack_s1_setup_response(s1ap_args_t s1ap_args, srslte::byte_buff succ->procedureCode = LIBLTE_S1AP_PROC_ID_S1SETUP; succ->criticality = LIBLTE_S1AP_CRITICALITY_IGNORE; succ->choice_type = LIBLTE_S1AP_SUCCESSFULOUTCOME_CHOICE_S1SETUPRESPONSE; - + LIBLTE_S1AP_MESSAGE_S1SETUPRESPONSE_STRUCT* s1_resp=(LIBLTE_S1AP_MESSAGE_S1SETUPRESPONSE_STRUCT*)&succ->choice; s1_resp->ext=false; - + //MME Name s1_resp->MMEname_present=true; s1_resp->MMEname.ext=false; From 543cdf8566527a4b590dd11109a57ebe5fcf5897 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 22 Feb 2018 11:51:57 +0000 Subject: [PATCH 052/143] Adding handling of service request when no ECM context is present. --- srsepc/src/mme/s1ap_nas_transport.cc | 21 +++++++++++++++++++++ srsepc/src/spgw/spgw.cc | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 96834c3ba..2fa520c2f 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -651,9 +651,30 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, } else { + ue_ecm_ctx_t ue_ecm_ctx; //UE not connect. Connect normally. m_s1ap_log->console("Service Request -- User without ECM context\n"); m_s1ap_log->info("Service Request -- User without ECM context\n"); + //Create ECM context + ue_ecm_ctx.imsi = ue_emm_ctx->imsi; + ue_ecm_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + ue_emm_ctx->mme_ue_s1ap_id = ue_ecm_ctx.mme_ue_s1ap_id; + //Set eNB information + ue_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; + memcpy(&ue_ecm_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + + //Save whether secure ESM information transfer is necessary + ue_ecm_ctx.eit = false; + + //Initialize E-RABs + for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) + { + ue_ecm_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED; + ue_ecm_ctx.erabs_ctx[i].erab_id = i; + } + memcpy(&ue_ecm_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); + m_mme_gtpc->send_create_session_request(ue_ecm_ctx.imsi, ue_ecm_ctx.mme_ue_s1ap_id); } } else diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index 55f19818d..7bc47f496 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -385,9 +385,10 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg) { m_spgw_log->error("Mis-match between packet bytes and sent bytes: Sent: %d, Packet: %d \n",n,msg->N_bytes); } + + gettimeofday(&t_now, NULL); t_delta.tv_sec = t_now.tv_sec - m_t_last_dl.tv_sec; t_delta.tv_usec = t_now.tv_sec - m_t_last_dl.tv_usec; - gettimeofday(&t_now, NULL); if(t_delta.tv_sec>=5) { m_t_last_dl = t_now; From b233e9e1aeea153d5ada13700592bcbfdb3a1ed1 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 22 Feb 2018 15:50:05 +0000 Subject: [PATCH 053/143] Fixing bug with k_enb generation. Fixing issue with enb_ue_s1ap_id for service requests without ECM context. --- srsepc/src/mme/s1ap_nas_transport.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index e8c7f1815..627851d59 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -472,6 +472,10 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, std::map::iterator it = m_s1ap->m_tmsi_to_imsi.find(m_tmsi); if(it == m_s1ap->m_tmsi_to_imsi.end()) { + + m_s1ap_log->console("Attach Request -- Could not find M-TMSI 0x%x", m_tmsi); + m_s1ap_log->info("Attach Request -- Could not find M-TMSI 0x%x", m_tmsi); + //Could not find IMSI from M-TMSI, send Id request ue_emm_ctx_t tmp_ue_emm_ctx; ue_ecm_ctx_t ue_ecm_ctx; @@ -653,6 +657,8 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, else { ue_ecm_ctx_t ue_ecm_ctx; + ue_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; + //UE not connect. Connect normally. m_s1ap_log->console("Service Request -- User without ECM context\n"); m_s1ap_log->info("Service Request -- User without ECM context\n"); @@ -675,6 +681,10 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, } memcpy(&ue_ecm_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); + + //Re-generate K_eNB + liblte_security_generate_k_enb(ue_emm_ctx->security_ctxt.k_asme, ue_emm_ctx->security_ctxt.ul_nas_count, ue_emm_ctx->security_ctxt.k_enb); + m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",ue_emm_ctx->security_ctxt.ul_nas_count); m_mme_gtpc->send_create_session_request(ue_ecm_ctx.imsi, ue_ecm_ctx.mme_ue_s1ap_id); } } From 7dd734510bafdd11014bd690d9a55950dd541015 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 22 Feb 2018 18:38:25 +0000 Subject: [PATCH 054/143] added EMM cause 'CS not avilable' and ESM cause 'PDN type only IPv4 allowed.' --- srsepc/src/mme/s1ap_nas_transport.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 627851d59..58872b194 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -1561,10 +1561,13 @@ s1ap_nas_transport::pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *u attach_accept.guti.guti.mme_code, attach_accept.guti.guti.m_tmsi); + //Set EMM cause to no CS available + attach_accept.emm_cause_present=true; + attach_accept.emm_cause=18; + //Make sure all unused options are set to false attach_accept.lai_present=false; attach_accept.ms_id_present=false; - attach_accept.emm_cause_present=false; attach_accept.t3402_present=false; attach_accept.t3423_present=false; attach_accept.equivalent_plmns_present=false; @@ -1608,7 +1611,8 @@ s1ap_nas_transport::pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *u act_def_eps_bearer_context_req.radio_prio_present = false; act_def_eps_bearer_context_req.packet_flow_id_present = false; act_def_eps_bearer_context_req.apn_ambr_present = false; - act_def_eps_bearer_context_req.esm_cause_present = false; + act_def_eps_bearer_context_req.esm_cause_present = true; + act_def_eps_bearer_context_req.esm_cause = 50; uint8_t sec_hdr_type =2; ue_emm_ctx->security_ctxt.dl_nas_count++; From d913fdd499cee9760dccbbc4fe134b5aa5c23166 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 23 Feb 2018 10:18:13 +0000 Subject: [PATCH 055/143] Adding EMM information message. --- srsepc/hdr/mme/s1ap_nas_transport.h | 2 +- srsepc/src/mme/s1ap_nas_transport.cc | 46 ++++++++++++++++++---------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index b8eb98805..63253dcb0 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -94,7 +94,7 @@ public: bool pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx, LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctxt, struct srslte::gtpc_pdn_address_allocation_ie *paa, srslte::byte_buffer_t *nas_buffer); bool pack_identity_request(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id); - bool pack_emm_information(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id); + bool pack_emm_information(ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg); void log_unhandled_attach_request_ies(const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT *attach_req); void log_unhandled_pdn_con_request_ies(const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT *pdn_con_req); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 58872b194..b5c2b8531 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -837,6 +837,13 @@ s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, u return false; } m_mme_gtpc->send_modify_bearer_request(&ue_ecm_ctx->erabs_ctx[act_bearer.eps_bearer_id]); + + //Send reply to eNB + m_s1ap_log->console("Packing EMM infromationi\n"); + *reply_flag = pack_emm_information(ue_ecm_ctx, reply_msg); + m_s1ap_log->console("Sending EMM infromation, bytes %d\n",reply_msg->N_bytes); + m_s1ap_log->info("Sending EMM infromation\n"); + return true; } @@ -1536,6 +1543,7 @@ s1ap_nas_transport::pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *u //Attach accept attach_accept.eps_attach_result = LIBLTE_MME_EPS_ATTACH_RESULT_EPS_ONLY; + //attach_accept.eps_attach_result = LIBLTE_MME_EPS_ATTACH_RESULT_COMBINED_EPS_IMSI_ATTACH; //Mandatory //FIXME: Set t3412 from config attach_accept.t3412.unit = LIBLTE_MME_GPRS_TIMER_UNIT_1_MINUTE; // GPRS 1 minute unit @@ -1562,6 +1570,7 @@ s1ap_nas_transport::pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *u attach_accept.guti.guti.m_tmsi); //Set EMM cause to no CS available + //attach_accept.emm_cause_present=false; attach_accept.emm_cause_present=true; attach_accept.emm_cause=18; @@ -1611,8 +1620,8 @@ s1ap_nas_transport::pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *u act_def_eps_bearer_context_req.radio_prio_present = false; act_def_eps_bearer_context_req.packet_flow_id_present = false; act_def_eps_bearer_context_req.apn_ambr_present = false; - act_def_eps_bearer_context_req.esm_cause_present = true; - act_def_eps_bearer_context_req.esm_cause = 50; + act_def_eps_bearer_context_req.esm_cause_present = false; + //act_def_eps_bearer_context_req.esm_cause = 50; uint8_t sec_hdr_type =2; ue_emm_ctx->security_ctxt.dl_nas_count++; @@ -1692,7 +1701,7 @@ s1ap_nas_transport::pack_identity_request(srslte::byte_buffer_t *reply_msg, uint } bool -s1ap_nas_transport::pack_emm_information(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id) +s1ap_nas_transport::pack_emm_information( ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_msg) { srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); @@ -1710,8 +1719,8 @@ s1ap_nas_transport::pack_emm_information(srslte::byte_buffer_t *reply_msg, uint3 //Setup Dw NAS structure LIBLTE_S1AP_MESSAGE_DOWNLINKNASTRANSPORT_STRUCT *dw_nas = &init->choice.DownlinkNASTransport; dw_nas->ext=false; - dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = mme_ue_s1ap_id;//FIXME Change name - dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = enb_ue_s1ap_id; + dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ecm_ctx->mme_ue_s1ap_id;//FIXME Change name + dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ecm_ctx->enb_ue_s1ap_id; dw_nas->HandoverRestrictionList_present=false; dw_nas->SubscriberProfileIDforRFP_present=false; @@ -1727,20 +1736,12 @@ s1ap_nas_transport::pack_emm_information(srslte::byte_buffer_t *reply_msg, uint3 emm_info.utc_and_local_time_zone_present = false; emm_info.net_dst_present = false; - //Integrity check - ue_ecm_ctx_t * ue_ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); - if(ue_ecm_ctx == NULL) - { - return false; - } - ue_emm_ctx_t * ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); - if(ue_emm_ctx == NULL) - { + ue_emm_ctx_t *ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); + if(ue_emm_ctx ==NULL) return false; - } uint8_t sec_hdr_type =2; - ue_emm_ctx->security_ctxt.dl_nas_count++; + //ue_emm_ctx->security_ctxt.dl_nas_count++; LIBLTE_ERROR_ENUM err = liblte_mme_pack_emm_information_msg(&emm_info, sec_hdr_type, ue_emm_ctx->security_ctxt.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); if(err != LIBLTE_SUCCESS) { @@ -1760,9 +1761,20 @@ s1ap_nas_transport::pack_emm_information(srslte::byte_buffer_t *reply_msg, uint3 ); memcpy(&nas_buffer->msg[1],mac,4); + //Copy NAS PDU to Downlink NAS Trasport message buffer + memcpy(dw_nas->NAS_PDU.buffer, nas_buffer->msg, nas_buffer->N_bytes); + dw_nas->NAS_PDU.n_octets = nas_buffer->N_bytes; + //Pack Downlink NAS Transport Message + err = liblte_s1ap_pack_s1ap_pdu(&tx_pdu, (LIBLTE_BYTE_MSG_STRUCT *) reply_msg); + if(err != LIBLTE_SUCCESS) + { + m_s1ap_log->error("Error packing Dw NAS Transport: EMM Info\n"); + m_s1ap_log->console("Error packing Downlink NAS Transport: EMM Info\n"); + return false; + } - m_s1ap_log->info("Packed \n"); + m_s1ap_log->info("Packed UE EMM information\n"); return true; } From 669ef9816fdae1374ba3e4bfcab65eaa0571cffe Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 26 Feb 2018 10:39:40 +0000 Subject: [PATCH 056/143] Added packing of TMSI to mobile station identity IE. --- lib/include/srslte/asn1/liblte_mme.h | 1 + lib/src/asn1/liblte_mme.cc | 64 +++++++++++++++++++--------- srsepc/src/mme/s1ap_nas_transport.cc | 24 ++++++++--- 3 files changed, 62 insertions(+), 27 deletions(-) diff --git a/lib/include/srslte/asn1/liblte_mme.h b/lib/include/srslte/asn1/liblte_mme.h index 78e2cae69..85b8b2241 100644 --- a/lib/include/srslte/asn1/liblte_mme.h +++ b/lib/include/srslte/asn1/liblte_mme.h @@ -175,6 +175,7 @@ typedef struct{ uint8 imsi[15]; uint8 imei[15]; uint8 imeisv[16]; + uint32 tmsi; }LIBLTE_MME_MOBILE_ID_STRUCT; // Functions LIBLTE_ERROR_ENUM liblte_mme_pack_mobile_id_ie(LIBLTE_MME_MOBILE_ID_STRUCT *mobile_id, diff --git a/lib/src/asn1/liblte_mme.cc b/lib/src/asn1/liblte_mme.cc index ea7729519..da79fb791 100644 --- a/lib/src/asn1/liblte_mme.cc +++ b/lib/src/asn1/liblte_mme.cc @@ -297,6 +297,7 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_mobile_id_ie(LIBLTE_MME_MOBILE_ID_STRUCT *mob { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8 *id; + uint32 id32; uint32 i; uint8 length; bool odd = false; @@ -317,6 +318,11 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_mobile_id_ie(LIBLTE_MME_MOBILE_ID_STRUCT *mob id = mobile_id->imeisv; length = 9; odd = false; + }else if(LIBLTE_MME_MOBILE_ID_TYPE_TMSI == mobile_id->type_of_id){ + id32 = mobile_id->tmsi; + length = 4; + odd = false; + } }else{ // FIXME: Not handling these IDs return(err); @@ -325,30 +331,48 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_mobile_id_ie(LIBLTE_MME_MOBILE_ID_STRUCT *mob // Length **ie_ptr = length; *ie_ptr += 1; - - // | Identity digit 1 | odd/even | Id type | - if(odd) + if(LIBLTE_MME_MOBILE_ID_TYPE_TMSI != mobile_id->type_of_id) { - **ie_ptr = (id[0] << 4) | (1 << 3) | mobile_id->type_of_id; - }else{ - **ie_ptr = (id[0] << 4) | (0 << 3) | mobile_id->type_of_id; - } - *ie_ptr += 1; + // | Identity digit 1 | odd/even | Id type | + if(odd) + { + **ie_ptr = (id[0] << 4) | (1 << 3) | mobile_id->type_of_id; + }else{ + **ie_ptr = (id[0] << 4) | (0 << 3) | mobile_id->type_of_id; + } + *ie_ptr += 1; - // | Identity digit p+1 | Identity digit p | - for(i=0; i<7; i++) - { - (*ie_ptr)[i] = (id[i*2+2] << 4) | id[i*2+1]; - } - *ie_ptr += 7; - if(!odd) - { - **ie_ptr = 0xF0 | id[15]; - *ie_ptr += 1; + + // | Identity digit p+1 | Identity digit p | + for(i=0; i<7; i++) + { + (*ie_ptr)[i] = (id[i*2+2] << 4) | id[i*2+1]; + } + *ie_ptr += 7; + if(!odd) + { + **ie_ptr = 0xF0 | id[15]; + *ie_ptr += 1; + } + + err = LIBLTE_SUCCESS; } + else{ - err = LIBLTE_SUCCESS; - } + **ie_ptr = (0xFF << 4) | (0 << 3) | mobile_id->type_of_id; + *ie_ptr += 1; + //4-Byte based ids + **ie_ptr = (id32 >> 24) & 0xFF; + *ie_ptr += 1; + **ie_ptr = (id32 >> 16) & 0xFF; + *ie_ptr += 1; + **ie_ptr = (id32 >> 8) & 0xFF; + *ie_ptr += 1; + **ie_ptr = id32 & 0xFF; + *ie_ptr += 1; + + err = LIBLTE_SUCCESS; + } return(err); } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index b5c2b8531..736eb4d3d 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -1542,8 +1542,9 @@ s1ap_nas_transport::pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *u } //Attach accept - attach_accept.eps_attach_result = LIBLTE_MME_EPS_ATTACH_RESULT_EPS_ONLY; - //attach_accept.eps_attach_result = LIBLTE_MME_EPS_ATTACH_RESULT_COMBINED_EPS_IMSI_ATTACH; + //attach_accept.eps_attach_result = LIBLTE_MME_EPS_ATTACH_RESULT_EPS_ONLY; + attach_accept.eps_attach_result = LIBLTE_MME_EPS_ATTACH_RESULT_COMBINED_EPS_IMSI_ATTACH; + //Mandatory //FIXME: Set t3412 from config attach_accept.t3412.unit = LIBLTE_MME_GPRS_TIMER_UNIT_1_MINUTE; // GPRS 1 minute unit @@ -1570,13 +1571,22 @@ s1ap_nas_transport::pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *u attach_accept.guti.guti.m_tmsi); //Set EMM cause to no CS available - //attach_accept.emm_cause_present=false; - attach_accept.emm_cause_present=true; - attach_accept.emm_cause=18; + attach_accept.emm_cause_present=false; + //attach_accept.emm_cause_present=true; + //attach_accept.emm_cause=18; + + //Set up LAI for combined EPS/IMSI attach + //attach_accept.lai_present=false; + attach_accept.lai_present=true; + attach_accept.lai.mcc = mcc; + attach_accept.lai.mnc = mnc; + attach_accept.lai.lac = 001; + + attach_accept.ms_id_present=true; + attach_accept.ms_id.type_of_id = LIBLTE_MME_MOBILE_ID_TYPE_TMSI; + attach_accept.ms_id.tmsi = attach_accept.guti.guti.m_tmsi; //Make sure all unused options are set to false - attach_accept.lai_present=false; - attach_accept.ms_id_present=false; attach_accept.t3402_present=false; attach_accept.t3423_present=false; attach_accept.equivalent_plmns_present=false; From d301d7599f40fcb0bf6fa0205a43c8b2aaf9a4cc Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 26 Feb 2018 16:03:11 +0000 Subject: [PATCH 057/143] Quick and dirty hack to not send activate default eps bearer when a service request is received. --- srsepc/hdr/mme/mme_gtpc.h | 4 ++-- srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h | 2 +- srsepc/hdr/spgw/spgw.h | 2 +- srsepc/src/mme/mme_gtpc.cc | 8 ++++---- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 15 +++++++++++---- srsepc/src/mme/s1ap_nas_transport.cc | 16 +++++++++------- srsepc/src/spgw/spgw.cc | 4 ++-- 7 files changed, 30 insertions(+), 21 deletions(-) diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index 402a52a99..8909e89e2 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -48,8 +48,8 @@ public: bool init(srslte::log_filter *mme_gtpc_log); uint32_t get_new_ctrl_teid(); - void send_create_session_request(uint64_t imsi, uint32_t mme_s1ap_id); - void handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu); + void send_create_session_request(uint64_t imsi, uint32_t mme_s1ap_id, bool pack_attach); + void handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pack_attach); void send_modify_bearer_request(erab_ctx_t *bearer_ctx); void handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu); void send_delete_session_request(ue_ecm_ctx_t *ue_ecm_ctx); diff --git a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h index 44458aea6..1886b9d50 100644 --- a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h @@ -48,7 +48,7 @@ public: void init(void); //bool send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, struct srslte::gtpc_create_session_response *cs_resp, struct srslte::gtpc_f_teid_ie sgw_ctrl_fteid); - bool send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, ue_ecm_ctx_t *ecm_ctx, erab_ctx_t *erab_ctx); + bool send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, ue_ecm_ctx_t *ecm_ctx, erab_ctx_t *erab_ctx, bool pack_attach); bool handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT *in_ctxt_resp); bool handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT *ue_rel, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool send_ue_context_release_command(ue_ecm_ctx_t *ecm_ctx, srslte::byte_buffer_t *reply_buffer); diff --git a/srsepc/hdr/spgw/spgw.h b/srsepc/hdr/spgw/spgw.h index f39674ba7..3837dcf08 100644 --- a/srsepc/hdr/spgw/spgw.h +++ b/srsepc/hdr/spgw/spgw.h @@ -73,7 +73,7 @@ public: void stop(); void run_thread(); - void handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu); + void handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu,bool pack_attach); void handle_modify_bearer_request(struct srslte::gtpc_pdu *mb_req_pdu, struct srslte::gtpc_pdu *mb_resp_pdu); void handle_delete_session_request(struct srslte::gtpc_pdu *del_req_pdu, struct srslte::gtpc_pdu *del_resp_pdu); diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index e6f4511df..dd8c7c617 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -88,7 +88,7 @@ mme_gtpc::get_new_ctrl_teid() return m_next_ctrl_teid++; //FIXME Use a Id pool? } void -mme_gtpc::send_create_session_request(uint64_t imsi, uint32_t mme_ue_s1ap_id) +mme_gtpc::send_create_session_request(uint64_t imsi, uint32_t mme_ue_s1ap_id, bool pack_attach) { m_mme_gtpc_log->info("Sending Create Session Request.\n"); m_mme_gtpc_log->console("Sending Create Session Request.\n"); @@ -125,12 +125,12 @@ mme_gtpc::send_create_session_request(uint64_t imsi, uint32_t mme_ue_s1ap_id) //Save RX Control TEID m_teid_to_mme_s1ap_id.insert(std::pair(cs_req->sender_f_teid.teid, mme_ue_s1ap_id)); - m_spgw->handle_create_session_request(cs_req, &cs_resp_pdu); + m_spgw->handle_create_session_request(cs_req, &cs_resp_pdu, pack_attach); } void -mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu) +mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pack_attach) { struct srslte::gtpc_create_session_response *cs_resp = & cs_resp_pdu->choice.create_session_response; m_mme_gtpc_log->info("Received Create Session Response\n"); @@ -206,7 +206,7 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu) erab_ctx->sgw_ctrl_fteid = sgw_ctrl_fteid; erab_ctx->sgw_s1u_fteid = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid; - m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, erab_ctx); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, erab_ctx, pack_attach); } diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index c68301ff0..e3332e2d1 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -79,8 +79,10 @@ s1ap_ctx_mngmt_proc::init(void) bool s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, ue_ecm_ctx_t *ecm_ctx, - erab_ctx_t *erab_ctx) + erab_ctx_t *erab_ctx, + bool pack_attach) { + int s1mme = m_s1ap->get_s1_mme(); //Prepare reply PDU @@ -159,16 +161,21 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, m_s1ap_log->info_hex(emm_ctx->security_ctxt.k_enb, 32, "Initial Context Setup Request -- Key eNB\n"); srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); - m_s1ap_nas_transport->pack_attach_accept(emm_ctx, ecm_ctx, erab_ctx_req, &erab_ctx->pdn_addr_alloc, nas_buffer); + if(pack_attach) + { + pack_attach = false; + m_s1ap_nas_transport->pack_attach_accept(emm_ctx, ecm_ctx, erab_ctx_req, &erab_ctx->pdn_addr_alloc, nas_buffer); + + } - LIBLTE_ERROR_ENUM err = liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)reply_buffer); if(err != LIBLTE_SUCCESS) { m_s1ap_log->error("Could not pack Initial Context Setup Request Message\n"); return false; } - //Send Reply to eNB + + //Send Reply to eNB ssize_t n_sent = sctp_send(s1mme,reply_buffer->msg, reply_buffer->N_bytes, &ecm_ctx->enb_sri, 0); if(n_sent == -1) { diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 736eb4d3d..e84d19b78 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -578,7 +578,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); //Create session request m_s1ap_log->console("GUTI Attach -- NAS Integrity OK."); - m_mme_gtpc->send_create_session_request(ue_emm_ctx->imsi, ue_emm_ctx->mme_ue_s1ap_id); + m_mme_gtpc->send_create_session_request(ue_emm_ctx->imsi, ue_emm_ctx->mme_ue_s1ap_id,true); *reply_flag = false; //No reply needed return true; } @@ -652,7 +652,7 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, m_s1ap_log->info("Service Request -- User has ECM context already\n"); m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); int default_bearer_id = 5; - m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(ue_emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[default_bearer_id]); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(ue_emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[default_bearer_id],false); } else { @@ -685,7 +685,9 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, //Re-generate K_eNB liblte_security_generate_k_enb(ue_emm_ctx->security_ctxt.k_asme, ue_emm_ctx->security_ctxt.ul_nas_count, ue_emm_ctx->security_ctxt.k_enb); m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",ue_emm_ctx->security_ctxt.ul_nas_count); - m_mme_gtpc->send_create_session_request(ue_ecm_ctx.imsi, ue_ecm_ctx.mme_ue_s1ap_id); + + m_mme_gtpc->send_create_session_request(ue_ecm_ctx.imsi, ue_ecm_ctx.mme_ue_s1ap_id,false); + // m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(ue_); } } else @@ -798,7 +800,7 @@ s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas { //FIXME The packging of GTP-C messages is not ready. //This means that GTP-U tunnels are created with function calls, as opposed to GTP-C. - m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi, ue_ecm_ctx->mme_ue_s1ap_id); + m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi, ue_ecm_ctx->mme_ue_s1ap_id,true); *reply_flag = false; //No reply needed } return true; @@ -867,7 +869,7 @@ s1ap_nas_transport::handle_esm_information_response(srslte::byte_buffer_t *nas_m //FIXME The packging of GTP-C messages is not ready. //This means that GTP-U tunnels are created with function calls, as opposed to GTP-C. - m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi, ue_ecm_ctx->mme_ue_s1ap_id); + m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi, ue_ecm_ctx->mme_ue_s1ap_id,true); return true; } @@ -1577,12 +1579,12 @@ s1ap_nas_transport::pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *u //Set up LAI for combined EPS/IMSI attach //attach_accept.lai_present=false; - attach_accept.lai_present=true; + attach_accept.lai_present=false; attach_accept.lai.mcc = mcc; attach_accept.lai.mnc = mnc; attach_accept.lai.lac = 001; - attach_accept.ms_id_present=true; + attach_accept.ms_id_present=false; attach_accept.ms_id.type_of_id = LIBLTE_MME_MOBILE_ID_TYPE_TMSI; attach_accept.ms_id.tmsi = attach_accept.guti.guti.m_tmsi; diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index 7bc47f496..6904b3ee3 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -437,7 +437,7 @@ spgw::get_new_ue_ipv4() } void -spgw::handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu) +spgw::handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu, bool pack_attach) { srslte::gtpc_header *header = &cs_resp_pdu->header; srslte::gtpc_create_session_response *cs_resp = &cs_resp_pdu->choice.create_session_response; @@ -492,7 +492,7 @@ spgw::handle_create_session_request(struct srslte::gtpc_create_session_request * cs_resp->paa.ipv4_present = true; cs_resp->paa.ipv4 = ue_ip; m_spgw_log->info("Sending Create Session Response\n"); - m_mme_gtpc->handle_create_session_response(cs_resp_pdu); + m_mme_gtpc->handle_create_session_response(cs_resp_pdu, pack_attach ); return; } From ea0585a772f5a787823336ba8249032db4571a27 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 26 Feb 2018 18:50:53 +0000 Subject: [PATCH 058/143] Quick hack to keep the IP in service request. --- srsepc/src/mme/mme_gtpc.cc | 3 +++ srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 7 ++++++- srsepc/src/mme/s1ap_nas_transport.cc | 3 ++- srsepc/src/spgw/spgw.cc | 8 ++++---- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index dd8c7c617..ab383bf52 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -157,6 +157,7 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pac } uint32_t mme_s1ap_id = id_it->second; + m_mme_gtpc_log->info("MME GTPC Ctrl TEID %d, MME UE S1AP Id %d\n", cs_resp_pdu->header.teid, mme_s1ap_id); //Get S-GW Control F-TEID srslte::gtpc_f_teid_ie sgw_ctrl_fteid; sgw_ctrl_fteid.teid = cs_resp_pdu->header.teid; @@ -168,9 +169,11 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pac return; } m_mme_gtpc_log->console("Create Session Response -- SPGW control TEID %d\n", sgw_ctrl_fteid.teid); + m_mme_gtpc_log->info("Create Session Response -- SPGW control TEID %d\n", sgw_ctrl_fteid.teid); in_addr s1u_addr; s1u_addr.s_addr = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.ipv4; m_mme_gtpc_log->console("Create Session Response -- SPGW S1-U Address: %s\n", inet_ntoa(s1u_addr)); + m_mme_gtpc_log->info("Create Session Response -- SPGW S1-U Address: %s\n", inet_ntoa(s1u_addr)); //Check UE Ipv4 address was allocated if(cs_resp->paa_present != true) diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index e3332e2d1..83b5c9594 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -203,7 +203,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, bool s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT *in_ctxt_resp) { - + static bool send_modify = false; uint32_t mme_ue_s1ap_id = in_ctxt_resp->MME_UE_S1AP_ID.MME_UE_S1AP_ID; ue_ecm_ctx_t *ue_ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); if (ue_ecm_ctx == NULL) @@ -244,6 +244,11 @@ s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_I m_s1ap_log->console("E-RAB Context -- eNB TEID 0x%x; eNB GTP-U Address %s\n", erab_ctx->enb_fteid.teid, enb_addr_str); } + if(send_modify) + { + m_mme_gtpc->send_modify_bearer_request(&ue_ecm_ctx->erabs_ctx[5]); + } + send_modify = true; return true; } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index e84d19b78..bdea825de 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -687,7 +687,8 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",ue_emm_ctx->security_ctxt.ul_nas_count); m_mme_gtpc->send_create_session_request(ue_ecm_ctx.imsi, ue_ecm_ctx.mme_ue_s1ap_id,false); - // m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(ue_); + m_s1ap_log->console("UE ESM Ctr TEID %d\n", ue_ecm_ctx.erabs_ctx[5].sgw_ctrl_fteid.teid); + // m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(ue_); } } else diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index 6904b3ee3..df62fa43b 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -338,7 +338,7 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg) dest_addr.s_addr = dest_ip; //m_spgw_log->console("IP version: %d\n", version); - //m_spgw_log->console("Received packet to IP: %s\n", inet_ntoa(dest_addr)); + m_spgw_log->console("Received packet to IP: %s\n", inet_ntoa(dest_addr)); pthread_mutex_lock(&m_mutex); gtp_fteid_it = m_ip_to_teid.find(dest_ip); @@ -351,7 +351,7 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg) if(ip_found == false) { - //m_spgw_log->console("IP Packet is not for any UE\n"); + m_spgw_log->console("IP Packet is not for any UE\n"); return; } struct sockaddr_in enb_addr; @@ -449,8 +449,8 @@ spgw::handle_create_session_request(struct srslte::gtpc_create_session_request * //Setup uplink user TEID uint64_t spgw_uplink_user_teid = get_new_user_teid(); //Allocate UE IP - in_addr_t ue_ip = get_new_ue_ipv4(); - + //in_addr_t ue_ip = get_new_ue_ipv4(); + in_addr_t ue_ip = inet_addr("172.16.0.2"); uint8_t default_bearer_id = 5; //Save the UE IP to User TEID map From f7348e8ddf05a4065bae35fd0e5de28731f15197 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 26 Feb 2018 19:37:41 +0000 Subject: [PATCH 059/143] Added print to show unhandled S1AP messages. --- srsepc/src/mme/s1ap.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 3cd47d6b9..c0c8ee630 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -250,7 +250,8 @@ s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, stru 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 intiating message: %s\n", liblte_s1ap_initiatingmessage_choice_text[msg->choice_type]); + m_s1ap_log->error("Unhandled S1AP intiating message: %s\n", liblte_s1ap_initiatingmessage_choice_text[msg->choice_type]); + m_s1ap_log->console("Unhandled S1APintiating message: %s\n", liblte_s1ap_initiatingmessage_choice_text[msg->choice_type]); } //Send Reply to eNB if(reply_flag == true) From ecb846717c8304059b6cfa8d4e63f19bfb044443 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 27 Feb 2018 13:33:43 +0000 Subject: [PATCH 060/143] Starting to handle UE capability info indication --- srsepc/hdr/mme/s1ap.h | 6 ++- srsepc/hdr/mme/s1ap_ue_cap_info.h | 60 +++++++++++++++++++++++ srsepc/src/mme/s1ap.cc | 4 ++ srsepc/src/mme/s1ap_ue_cap_info.cc | 77 ++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 srsepc/hdr/mme/s1ap_ue_cap_info.h create mode 100644 srsepc/src/mme/s1ap_ue_cap_info.cc diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 774831840..3f9f035e0 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -44,6 +44,7 @@ #include "mme/s1ap_mngmt_proc.h" #include "mme/s1ap_nas_transport.h" #include "mme/s1ap_ctx_mngmt_proc.h" +#include "mme/s1ap_ue_cap_info.h" #include "mme/mme_gtpc.h" #include "hss/hss.h" @@ -100,8 +101,9 @@ public: srslte::log_filter *m_s1ap_log; s1ap_mngmt_proc* m_s1ap_mngmt_proc; - s1ap_nas_transport* m_s1ap_nas_transport; - s1ap_ctx_mngmt_proc* m_s1ap_ctx_mngmt_proc; + s1ap_nas_transport* m_s1ap_nas_transport; + s1ap_ctx_mngmt_proc* m_s1ap_ctx_mngmt_proc; + s1ap_ue_cap_info* m_s1ap_ue_cap_info; std::map m_tmsi_to_imsi; diff --git a/srsepc/hdr/mme/s1ap_ue_cap_info.h b/srsepc/hdr/mme/s1ap_ue_cap_info.h new file mode 100644 index 000000000..59bb37ea3 --- /dev/null +++ b/srsepc/hdr/mme/s1ap_ue_cap_info.h @@ -0,0 +1,60 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2017 Software Radio Systems Limited + * + * \section LICENSE + * + * This file is part of srsLTE. + * + * srsLTE is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * srsLTE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * A copy of the GNU Affero General Public License can be found in + * the LICENSE file in the top-level directory of this distribution + * and at http://www.gnu.org/licenses/. + * + */ +#ifndef S1AP_UE_CAP_INFO_H +#define S1AP_UE_CAP_INFO_H + +#include "srslte/asn1/liblte_s1ap.h" +#include "srslte/common/common.h" +#include "mme/s1ap_common.h" +#include "srslte/common/log_filter.h" + +namespace srsepc{ + +class s1ap; + +class s1ap_ue_cap_info +{ +public: + + static s1ap_ue_cap_info *m_instance; + + static s1ap_ue_cap_info* get_instance(void); + static void cleanup(void); + void init(void); + + bool handle_ue_capability_info_indication(LIBLTE_S1AP_MESSAGE_UECAPABILITYINFOINDICATION_STRUCT *msg, sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); + +private: + s1ap_ue_cap_info(); + virtual ~s1ap_ue_cap_info(); + + s1ap* m_s1ap; + srslte::log_filter *m_s1ap_log; +}; + +} //namespace srsepc + +#endif //S1AP_MNGMT_PROC diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index c0c8ee630..d0b765fd4 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -249,6 +249,10 @@ s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, stru 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); break; + case LIBLTE_S1AP_PROC_ID_UECAPABILITYINFOINDICATION: + m_s1ap_log->info("Received UE Context Release Request Message.\n"); + m_s1ap_ue_cap_info->handle_ue_capability_info_indication(&msg->choice.UECapabilityInfoIndication, enb_sri, reply_buffer, &reply_flag); + break; default: m_s1ap_log->error("Unhandled S1AP intiating message: %s\n", liblte_s1ap_initiatingmessage_choice_text[msg->choice_type]); m_s1ap_log->console("Unhandled S1APintiating message: %s\n", liblte_s1ap_initiatingmessage_choice_text[msg->choice_type]); diff --git a/srsepc/src/mme/s1ap_ue_cap_info.cc b/srsepc/src/mme/s1ap_ue_cap_info.cc new file mode 100644 index 000000000..357bb507c --- /dev/null +++ b/srsepc/src/mme/s1ap_ue_cap_info.cc @@ -0,0 +1,77 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2017 Software Radio Systems Limited + * + * \section LICENSE + * + * This file is part of srsLTE. + * + * srsLTE is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * srsLTE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * A copy of the GNU Affero General Public License can be found in + * the LICENSE file in the top-level directory of this distribution + * and at http://www.gnu.org/licenses/. + * + */ +#include "mme/s1ap.h" +#include "mme/s1ap_ue_cap_info.h" + +namespace srsepc{ + +s1ap_ue_cap_info* s1ap_ue_cap_info::m_instance = NULL; +boost::mutex s1ap_ue_cap_info_instance_mutex; + + +s1ap_ue_cap_info::s1ap_ue_cap_info() +{ +} + +s1ap_ue_cap_info::~s1ap_ue_cap_info() +{ +} + +s1ap_ue_cap_info* +s1ap_ue_cap_info::get_instance(void) +{ + boost::mutex::scoped_lock lock(s1ap_ue_cap_info_instance_mutex); + if(NULL == m_instance) { + m_instance = new s1ap_ue_cap_info(); + } + return(m_instance); +} + +void +s1ap_ue_cap_info::cleanup(void) +{ + boost::mutex::scoped_lock lock(s1ap_ue_cap_info_instance_mutex); + if(NULL != m_instance) { + delete m_instance; + m_instance = NULL; + } +} + +void +s1ap_ue_cap_info::init(void) +{ + m_s1ap = s1ap::get_instance(); + m_s1ap_log = m_s1ap->m_s1ap_log; +} + +bool +s1ap_ue_cap_info::handle_ue_capability_info_indication(LIBLTE_S1AP_MESSAGE_UECAPABILITYINFOINDICATION_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) +{ + m_s1ap_log->info("UE Capability Info Indication\n"); + return true; +} + +} //namespace srsepc From fc280e082fb9437ec63a42c9a2965b34932fd745 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 27 Feb 2018 14:45:11 +0000 Subject: [PATCH 061/143] Continuing to add UE capabilities info indication. --- srsepc/src/mme/s1ap.cc | 12 ++++++++---- srsepc/src/mme/s1ap_nas_transport.cc | 4 ++-- srsepc/src/mme/s1ap_ue_cap_info.cc | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index d0b765fd4..921e5ff84 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -82,12 +82,15 @@ s1ap::init(s1ap_args_t s1ap_args, srslte::log_filter *s1ap_log, hss_interface_s1 m_hss = hss_; //Init message handlers - m_s1ap_mngmt_proc = s1ap_mngmt_proc::get_instance(); //Managment procedures + m_s1ap_mngmt_proc = s1ap_mngmt_proc::get_instance(); //Managment procedures m_s1ap_mngmt_proc->init(); - m_s1ap_nas_transport = s1ap_nas_transport::get_instance(); //NAS Transport procedures + m_s1ap_nas_transport = s1ap_nas_transport::get_instance(); //NAS Transport procedures m_s1ap_nas_transport->init(m_hss); m_s1ap_ctx_mngmt_proc = s1ap_ctx_mngmt_proc::get_instance(); //Context Management Procedures m_s1ap_ctx_mngmt_proc->init(); + m_s1ap_ue_cap_info = s1ap_ue_cap_info::get_instance(); //UE Capability Information + m_s1ap_ue_cap_info->init(); + //Get pointer to GTP-C class m_mme_gtpc = mme_gtpc::get_instance(); @@ -126,6 +129,7 @@ s1ap::stop() s1ap_mngmt_proc::cleanup(); s1ap_nas_transport::cleanup(); s1ap_ctx_mngmt_proc::cleanup(); + s1ap_ue_cap_info::cleanup(); return; } @@ -226,7 +230,7 @@ s1ap::handle_s1ap_rx_pdu(srslte::byte_buffer_t *pdu, struct sctp_sndrcvinfo *enb } -bool +bool s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri) { bool reply_flag = false; @@ -249,7 +253,7 @@ s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, stru 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); break; - case LIBLTE_S1AP_PROC_ID_UECAPABILITYINFOINDICATION: + case LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_UECAPABILITYINFOINDICATION: m_s1ap_log->info("Received UE Context Release Request Message.\n"); m_s1ap_ue_cap_info->handle_ue_capability_info_indication(&msg->choice.UECapabilityInfoIndication, enb_sri, reply_buffer, &reply_flag); break; diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index bdea825de..f0767292c 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -1580,12 +1580,12 @@ s1ap_nas_transport::pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *u //Set up LAI for combined EPS/IMSI attach //attach_accept.lai_present=false; - attach_accept.lai_present=false; + attach_accept.lai_present=true; attach_accept.lai.mcc = mcc; attach_accept.lai.mnc = mnc; attach_accept.lai.lac = 001; - attach_accept.ms_id_present=false; + attach_accept.ms_id_present=true; attach_accept.ms_id.type_of_id = LIBLTE_MME_MOBILE_ID_TYPE_TMSI; attach_accept.ms_id.tmsi = attach_accept.guti.guti.m_tmsi; diff --git a/srsepc/src/mme/s1ap_ue_cap_info.cc b/srsepc/src/mme/s1ap_ue_cap_info.cc index 357bb507c..f06fde165 100644 --- a/srsepc/src/mme/s1ap_ue_cap_info.cc +++ b/srsepc/src/mme/s1ap_ue_cap_info.cc @@ -71,6 +71,7 @@ bool s1ap_ue_cap_info::handle_ue_capability_info_indication(LIBLTE_S1AP_MESSAGE_UECAPABILITYINFOINDICATION_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) { m_s1ap_log->info("UE Capability Info Indication\n"); + m_s1ap_log->console("UE Capability Info Indication\n"); return true; } From 01cf00700ac9c9be1e8d22ad61381e2d4ce964e7 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 6 Mar 2018 10:55:22 +0000 Subject: [PATCH 062/143] Adding DNS config options --- srsepc/hdr/mme/s1ap_common.h | 1 + srsepc/src/main.cc | 4 +++- srsepc/src/mme/s1ap_nas_transport.cc | 15 ++++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index c69eb05d1..145a94225 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -90,6 +90,7 @@ typedef struct{ uint16_t mnc; // BCD-coded with 0xF filler std::string mme_bind_addr; std::string mme_name; + std::string dns_addr; } s1ap_args_t; typedef struct{ diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index 3a931ddd2..c7c9e6057 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -52,7 +52,6 @@ typedef struct { int spgw_hex_limit; std::string hss_level; int hss_hex_limit; - std::string all_level; int all_hex_limit; std::string filename; @@ -83,6 +82,7 @@ parse_args(all_args_t *args, int argc, char* argv[]) { string mme_bind_addr; string spgw_bind_addr; string sgi_if_addr; + string dns_addr; string hss_db_file; string hss_auth_algo; string log_filename; @@ -105,6 +105,7 @@ parse_args(all_args_t *args, int argc, char* argv[]) { ("mme.mcc", bpo::value(&mcc)->default_value("001"), "Mobile Country Code") ("mme.mnc", bpo::value(&mnc)->default_value("01"), "Mobile Network Code") ("mme.mme_bind_addr", bpo::value(&mme_bind_addr)->default_value("127.0.0.1"),"IP address of MME for S1 connnection") + ("mme.dns_addr", bpo::value(&dns_addr)->default_value("8.8.8.8"),"IP address of the DNS server for the UEs") ("hss.db_file", bpo::value(&hss_db_file)->default_value("ue_db.csv"),".csv file that stores UE's keys") ("hss.auth_algo", bpo::value(&hss_auth_algo)->default_value("milenage"),"HSS uthentication algorithm.") ("spgw.gtpu_bind_addr", bpo::value(&spgw_bind_addr)->default_value("127.0.0.1"),"IP address of SP-GW for the S1-U connection") @@ -205,6 +206,7 @@ parse_args(all_args_t *args, int argc, char* argv[]) { args->mme_args.s1ap_args.mme_bind_addr = mme_bind_addr; args->mme_args.s1ap_args.mme_name = mme_name; + args->mme_args.s1ap_args.dns_addr = dns_addr; args->spgw_args.gtpu_bind_addr = spgw_bind_addr; args->spgw_args.sgi_if_addr = sgi_if_addr; args->hss_args.db_file = hss_db_file; diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index f0767292c..ab119041e 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -650,7 +650,7 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, //Delete eNB context and connect. m_s1ap_log->console("Service Request -- User has ECM context already\n"); m_s1ap_log->info("Service Request -- User has ECM context already\n"); - m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); + //m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); int default_bearer_id = 5; m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(ue_emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[default_bearer_id],false); } @@ -1622,10 +1622,15 @@ s1ap_nas_transport::pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *u act_def_eps_bearer_context_req.protocol_cnfg_opts.N_opts = 1; act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].id = 0x0d; act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].len = 4; - act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents[0] = 8; - act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents[1] = 8; - act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents[2] = 8; - act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents[3] = 8; + + struct sockaddr_in dns_addr; + inet_pton(AF_INET, m_s1ap->m_s1ap_args.dns_addr.c_str(), &(dns_addr.sin_addr)); + + memcpy(act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents,&dns_addr.sin_addr.s_addr, 4); + //act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents[0] = 8; + //act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents[1] = 8; + //act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents[2] = 8; + //act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents[3] = 8; //Make sure all unused options are set to false act_def_eps_bearer_context_req.negotiated_qos_present = false; From e9213f807dd270232645402bc79a1a33bef8f767 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 7 Mar 2018 12:17:49 +0000 Subject: [PATCH 063/143] Starting to change SPGW to handle release access bearers request. Changing MME GTPC entity to contain an IMSI to sgw_ctr_fteid and ctr_teid to IMSI maps. --- srsepc/hdr/mme/mme_gtpc.h | 3 ++- srsepc/hdr/mme/s1ap_common.h | 4 ++-- srsepc/src/mme/mme_gtpc.cc | 27 +++++++++++++++++++++++++++ srsepc/src/mme/s1ap_nas_transport.cc | 2 +- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index 8909e89e2..c1656afaf 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -68,7 +68,8 @@ private: in_addr_t m_mme_gtpc_ip; uint32_t m_next_ctrl_teid; - std::map m_teid_to_mme_s1ap_id; + std::map m_ctr_teid_to_imsi; + std::map m_imsi_to_ctr_fteid; }; diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index 1b5b0ea54..15f4e3c6d 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -127,7 +127,6 @@ typedef struct{ enum erab_state state; uint8_t erab_id; srslte::gtpc_f_teid_ie enb_fteid; - srslte::gtpc_f_teid_ie sgw_ctrl_fteid; srslte::gtpc_f_teid_ie sgw_s1u_fteid; srslte::gtpc_pdn_address_allocation_ie pdn_addr_alloc; } erab_ctx_t; @@ -148,8 +147,9 @@ typedef struct{ uint32_t mme_ue_s1ap_id; struct sctp_sndrcvinfo enb_sri; ecm_state_t ecm_state; + srslte::gtpc_f_teid_ie sgw_ctrl_fteid; + erab_ctx_t erabs_ctx[MAX_ERABS_PER_UE]; bool eit; - erab_ctx_t erabs_ctx[MAX_ERABS_PER_UE]; } ue_ecm_ctx_t; diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 70769c9ef..19bb0f96d 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -298,4 +298,31 @@ mme_gtpc::send_delete_session_request(ue_ecm_ctx_t *ue_ecm_ctx) //TODO Handle delete session response return; } + +void +mme_gtpc::send_release_access_bearers_request(ue_ecm_ctx_t *ecm_ctx) +{ + m_mme_gtpc_log->info("Sending GTP-C Delete Access Bearers Request\n"); + srslte::gtpc_pdu rel_req_pdu; + if(ecm_ctx->state != ECM_ ) + { + + } + srslte::gtpc_f_teid_ie *sgw_ctrl_fteid = NULL; + + srslte::gtpc_header *header = &rel_req_pdu.header; + header->teid_present = true; + header->teid = sgw_ctrl_fteid->teid; + header->type = srslte::GTPC_MSG_TYPE_RELEASE_ACCESS_BEARERS_REQUEST; + + srslte::gtpc_release_access_bearers_request *rel_req = &rel_req_pdu.choice.release_access_bearers_request; + del_req->cause.cause_value = srslte::GTPC_CAUSE_VALUE_ISR_DEACTIVATION; + m_mme_gtpc_log->info("GTP-C Release Access Berarers Request -- S-GW Control TEID %d\n", sgw_ctrl_fteid->teid ); + + srslte::gtpc_pdu del_resp_pdu; + m_spgw->handle_delete_session_request(&del_req_pdu, &del_resp_pdu); + + //TODO Handle delete session response + return; +} } //namespace srsepc diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index e49c3a05e..97f6149f6 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -707,7 +707,7 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",ue_emm_ctx->security_ctxt.ul_nas_count); //FIXME Send Modify context request OR send ctx release command and wait for the reply. m_mme_gtpc->send_create_session_request(ue_ecm_ctx.imsi, ue_ecm_ctx.mme_ue_s1ap_id,false); - m_s1ap_log->console("UE ESM Ctr TEID %d\n", ue_ecm_ctx.erabs_ctx[5].sgw_ctrl_fteid.teid); + m_s1ap_log->console("UE ESM Ctr TEID %d\n", ue_ecm_ctx.sgw_ctrl_fteid.teid); // m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(ue_); } } From e499fffe01aaaaa51d8ef4081c01c5e0a823e668 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 7 Mar 2018 14:58:08 +0000 Subject: [PATCH 064/143] Starting to save GTP-C context in a map, to keep the GTP-C connection even when the NAS connection is released. --- lib/include/srslte/asn1/gtpc_ies.h | 5 ++-- srsepc/hdr/mme/mme_gtpc.h | 6 +++- srsepc/src/mme/mme_gtpc.cc | 41 ++++++++++++++++++++-------- srsepc/src/mme/s1ap_nas_transport.cc | 8 +++--- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/lib/include/srslte/asn1/gtpc_ies.h b/lib/include/srslte/asn1/gtpc_ies.h index 35b5e6498..657fc7c16 100644 --- a/lib/include/srslte/asn1/gtpc_ies.h +++ b/lib/include/srslte/asn1/gtpc_ies.h @@ -400,7 +400,8 @@ enum gtpc_interface_type S2B_U_PGW_GTP_U_INTERFACE }; -struct gtpc_f_teid_ie + +typedef struct gtpc_f_teid_ie { bool ipv4_present; bool ipv6_present; @@ -408,7 +409,7 @@ struct gtpc_f_teid_ie uint32_t teid; in_addr_t ipv4; struct in6_addr ipv6; //FIXME -}; +} gtp_fteid_t; //TODO //TODO IEs between 8.22 and 8.28 missing diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index c1656afaf..992ccdae7 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -42,13 +42,17 @@ class mme_gtpc { public: + struct gtpc_ctx{ + srslte::gtp_fteid_t mme_ctr_fteid; + srslte::gtp_fteid_t sgw_ctr_fteid; + }; static mme_gtpc* get_instance(void); static void cleanup(void); bool init(srslte::log_filter *mme_gtpc_log); uint32_t get_new_ctrl_teid(); - void send_create_session_request(uint64_t imsi, uint32_t mme_s1ap_id, bool pack_attach); + void send_create_session_request(uint64_t imsi, bool pack_attach); void handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pack_attach); void send_modify_bearer_request(erab_ctx_t *bearer_ctx); void handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu); diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 19bb0f96d..3e35844b2 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -88,7 +88,7 @@ mme_gtpc::get_new_ctrl_teid() return m_next_ctrl_teid++; //FIXME Use a Id pool? } void -mme_gtpc::send_create_session_request(uint64_t imsi, uint32_t mme_ue_s1ap_id, bool pack_attach) +mme_gtpc::send_create_session_request(uint64_t imsi, bool pack_attach) { m_mme_gtpc_log->info("Sending Create Session Request.\n"); m_mme_gtpc_log->console("Sending Create Session Request.\n"); @@ -96,7 +96,6 @@ mme_gtpc::send_create_session_request(uint64_t imsi, uint32_t mme_ue_s1ap_id, bo struct srslte::gtpc_create_session_request *cs_req = &cs_req_pdu.choice.create_session_request; struct srslte::gtpc_pdu cs_resp_pdu; - //Initialize GTP-C message to zero bzero(&cs_req_pdu, sizeof(struct srslte::gtpc_pdu)); @@ -113,19 +112,39 @@ mme_gtpc::send_create_session_request(uint64_t imsi, uint32_t mme_ue_s1ap_id, bo cs_req->sender_f_teid.teid = get_new_ctrl_teid(); cs_req->sender_f_teid.ipv4 = m_mme_gtpc_ip; - m_mme_gtpc_log->info("Next control TEID: %lu \n", m_next_ctrl_teid); - m_mme_gtpc_log->info("Allocated control TEID: %lu \n", cs_req->sender_f_teid.teid); + m_mme_gtpc_log->info("Next MME control TEID: %lu \n", m_next_ctrl_teid); + m_mme_gtpc_log->info("Allocated MME control TEID: %lu \n", cs_req->sender_f_teid.teid); m_mme_gtpc_log->console("Creating Session Response -- IMSI: %015lu \n", imsi); m_mme_gtpc_log->console("Creating Session Response -- MME control TEID: %lu \n", cs_req->sender_f_teid.teid); + // APN strncpy(cs_req->apn, m_s1ap->m_s1ap_args.mme_apn.c_str(), sizeof(cs_req->apn)-1); cs_req->apn[sizeof(cs_req->apn)-1] = 0; // RAT Type //cs_req->rat_type = srslte::GTPC_RAT_TYPE::EUTRAN; - //Save RX Control TEID - m_teid_to_mme_s1ap_id.insert(std::pair(cs_req->sender_f_teid.teid, mme_ue_s1ap_id)); + //Check whether this UE is already registed + std::map::iterator it = m_imsi_to_gtpc_ctx.find(imsi); + if(it == m_imsi_to_ctr_fteid.end()) + { + m_mme_gtpc_log->warning("Create Session Request being called for an UE with an active GTP-C connection.\n"); + m_mme_gtpc_log->warning("Deleting previous GTP-C connection.\n"); + std::map::iterator jt = m_mme_ctr_teid_to_imsi.find(it->second.mme_ctr_fteid.teid); + if(jt == m_ctr_teid_to_imsi.end()) + { + m_mme_gtpc_log->error("Could not find IMSI from MME Ctrl TEID.\n") + } + else + { + m_ctr_teid_to_imsi.erease(jt); + } + m_imsi_to_ctr_fteid.erease(it); + //No need to send delete session request to the SPGW. + //The create session request will be interpreted as a new request and SPGW will delete locally in existing context. + } + //Save RX Control TEID + m_mme_ctr_teid_to_imsi.insert(std::pair(cs_req->sender_f_teid.teid, imsi)); m_spgw->handle_create_session_request(cs_req, &cs_resp_pdu, pack_attach); } @@ -190,14 +209,12 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pac //Save create session response info to E-RAB context ue_ecm_ctx_t *ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_s1ap_id); - if(ecm_ctx ==NULL) - { + if(ecm_ctx ==NULL){ m_mme_gtpc_log->error("Could not find UE ECM context\n"); return; } ue_emm_ctx_t *emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ecm_ctx->imsi); - if(emm_ctx ==NULL) - { + if(emm_ctx ==NULL){ m_mme_gtpc_log->error("Could not find UE EMM context\n"); return; } @@ -304,9 +321,9 @@ mme_gtpc::send_release_access_bearers_request(ue_ecm_ctx_t *ecm_ctx) { m_mme_gtpc_log->info("Sending GTP-C Delete Access Bearers Request\n"); srslte::gtpc_pdu rel_req_pdu; - if(ecm_ctx->state != ECM_ ) + if(ecm_ctx->state != ECM_STATE_CONNECTED ) { - + m_mme_gtpc_log->error("ECM State is not connected. No valid SGW Ctr TEID present\n"); } srslte::gtpc_f_teid_ie *sgw_ctrl_fteid = NULL; diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 97f6149f6..d897d3b2e 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -592,7 +592,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); //Create session request m_s1ap_log->console("GUTI Attach -- NAS Integrity OK."); - m_mme_gtpc->send_create_session_request(ue_emm_ctx->imsi, ue_emm_ctx->mme_ue_s1ap_id,true); + m_mme_gtpc->send_create_session_request(ue_emm_ctx->imsi,true); *reply_flag = false; //No reply needed return true; } @@ -706,7 +706,7 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, liblte_security_generate_k_enb(ue_emm_ctx->security_ctxt.k_asme, ue_emm_ctx->security_ctxt.ul_nas_count, ue_emm_ctx->security_ctxt.k_enb); m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",ue_emm_ctx->security_ctxt.ul_nas_count); //FIXME Send Modify context request OR send ctx release command and wait for the reply. - m_mme_gtpc->send_create_session_request(ue_ecm_ctx.imsi, ue_ecm_ctx.mme_ue_s1ap_id,false); + m_mme_gtpc->send_create_session_request(ue_ecm_ctx.imsi,false); m_s1ap_log->console("UE ESM Ctr TEID %d\n", ue_ecm_ctx.sgw_ctrl_fteid.teid); // m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(ue_); } @@ -823,7 +823,7 @@ s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas { //FIXME The packging of GTP-C messages is not ready. //This means that GTP-U tunnels are created with function calls, as opposed to GTP-C. - m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi, ue_ecm_ctx->mme_ue_s1ap_id,true); + m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi,true); *reply_flag = false; //No reply needed } return true; @@ -897,7 +897,7 @@ s1ap_nas_transport::handle_esm_information_response(srslte::byte_buffer_t *nas_m //FIXME The packging of GTP-C messages is not ready. //This means that GTP-U tunnels are created with function calls, as opposed to GTP-C. - m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi, ue_ecm_ctx->mme_ue_s1ap_id,true); + m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi,true); return true; } From 0c50ccef1c9cf7067fe0ae38d9912aaa023d0daf Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 7 Mar 2018 15:36:08 +0000 Subject: [PATCH 065/143] Changed create session request to keep GTPC context. --- srsepc/hdr/mme/mme_gtpc.h | 4 ++-- srsepc/src/mme/mme_gtpc.cc | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index 992ccdae7..3c5fa27bf 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -72,8 +72,8 @@ private: in_addr_t m_mme_gtpc_ip; uint32_t m_next_ctrl_teid; - std::map m_ctr_teid_to_imsi; - std::map m_imsi_to_ctr_fteid; + std::map m_mme_ctr_teid_to_imsi; + std::map m_imsi_to_gtpc_ctx; }; diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 3e35844b2..41f025083 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -124,21 +124,21 @@ mme_gtpc::send_create_session_request(uint64_t imsi, bool pack_attach) //cs_req->rat_type = srslte::GTPC_RAT_TYPE::EUTRAN; //Check whether this UE is already registed - std::map::iterator it = m_imsi_to_gtpc_ctx.find(imsi); - if(it == m_imsi_to_ctr_fteid.end()) + std::map::iterator it = m_imsi_to_gtpc_ctx.find(imsi); + if(it == m_imsi_to_gtpc_ctx.end()) { m_mme_gtpc_log->warning("Create Session Request being called for an UE with an active GTP-C connection.\n"); m_mme_gtpc_log->warning("Deleting previous GTP-C connection.\n"); std::map::iterator jt = m_mme_ctr_teid_to_imsi.find(it->second.mme_ctr_fteid.teid); - if(jt == m_ctr_teid_to_imsi.end()) + if(jt == m_mme_ctr_teid_to_imsi.end()) { - m_mme_gtpc_log->error("Could not find IMSI from MME Ctrl TEID.\n") + m_mme_gtpc_log->error("Could not find IMSI from MME Ctrl TEID. MME Ctr TEID: %d\n", it->second.mme_ctr_fteid.teid); } else { - m_ctr_teid_to_imsi.erease(jt); + m_mme_ctr_teid_to_imsi.erase(jt); } - m_imsi_to_ctr_fteid.erease(it); + m_imsi_to_gtpc_ctx.erase(it); //No need to send delete session request to the SPGW. //The create session request will be interpreted as a new request and SPGW will delete locally in existing context. } From 98345ed6a26d290d289593ab2402a3d9fc474941 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 7 Mar 2018 18:10:58 +0000 Subject: [PATCH 066/143] Adapting send modify bearer request to new GTP-C context --- srsepc/hdr/mme/mme_gtpc.h | 6 +-- srsepc/src/mme/mme_gtpc.cc | 75 +++++++++++++++++---------- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 2 +- srsepc/src/mme/s1ap_nas_transport.cc | 2 +- 4 files changed, 54 insertions(+), 31 deletions(-) diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index 3c5fa27bf..f94b05ccd 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -42,10 +42,10 @@ class mme_gtpc { public: - struct gtpc_ctx{ + typedef struct gtpc_ctx{ srslte::gtp_fteid_t mme_ctr_fteid; srslte::gtp_fteid_t sgw_ctr_fteid; - }; + }gtpc_ctx_t; static mme_gtpc* get_instance(void); static void cleanup(void); @@ -54,7 +54,7 @@ public: uint32_t get_new_ctrl_teid(); void send_create_session_request(uint64_t imsi, bool pack_attach); void handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pack_attach); - void send_modify_bearer_request(erab_ctx_t *bearer_ctx); + void send_modify_bearer_request(uint64_t imsi, erab_ctx_t *bearer_ctx); void handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu); void send_delete_session_request(ue_ecm_ctx_t *ue_ecm_ctx); diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 41f025083..fff721978 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -145,8 +145,14 @@ mme_gtpc::send_create_session_request(uint64_t imsi, bool pack_attach) //Save RX Control TEID m_mme_ctr_teid_to_imsi.insert(std::pair(cs_req->sender_f_teid.teid, imsi)); + + //Save GTP-C context + gtpc_ctx_t gtpc_ctx; + bzero(>pc_ctx,sizeof(gtpc_ctx_t)); + gtpc_ctx.mme_ctr_fteid = cs_req->sender_f_teid; + m_imsi_to_gtpc_ctx.insert(std::pair(imsi,gtpc_ctx)); m_spgw->handle_create_session_request(cs_req, &cs_resp_pdu, pack_attach); - + } void @@ -158,7 +164,7 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pac if (cs_resp_pdu->header.type != srslte::GTPC_MSG_TYPE_CREATE_SESSION_RESPONSE) { m_mme_gtpc_log->warning("Could not create GTPC session. Not a create session response\n"); - //TODO Handle err + //TODO Handle error return; } if (cs_resp->cause.cause_value != srslte::GTPC_CAUSE_VALUE_REQUEST_ACCEPTED){ @@ -166,30 +172,30 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pac //TODO Handle error return; } - - //Get MME_UE_S1AP_ID from the control TEID - std::map::iterator id_it = m_teid_to_mme_s1ap_id.find(cs_resp_pdu->header.teid); - if(id_it == m_teid_to_mme_s1ap_id.end()) + + //Get IMSI from the control TEID + std::map::iterator id_it = m_mme_ctr_teid_to_imsi.find(cs_resp_pdu->header.teid); + if(id_it == m_mme_ctr_teid_to_imsi.end()) { - //Could not find MME UE S1AP TEID - m_mme_gtpc_log->warning("Could not find MME UE S1AP TEID.\n"); + m_mme_gtpc_log->warning("Could not find IMSI from Ctrl TEID.\n"); return; } - uint32_t mme_s1ap_id = id_it->second; + uint64_t imsi = id_it->second; + + m_mme_gtpc_log->info("MME GTPC Ctrl TEID %d, IMSI %d\n", cs_resp_pdu->header.teid, imsi); - m_mme_gtpc_log->info("MME GTPC Ctrl TEID %d, MME UE S1AP Id %d\n", cs_resp_pdu->header.teid, mme_s1ap_id); //Get S-GW Control F-TEID - srslte::gtpc_f_teid_ie sgw_ctrl_fteid; - sgw_ctrl_fteid.teid = cs_resp_pdu->header.teid; - sgw_ctrl_fteid.ipv4 = 0; //FIXME This is not used for now. In the future it will be obtained from the socket addr_info + srslte::gtp_fteid_t sgw_ctr_fteid; + 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 if (cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid_present == false){ m_mme_gtpc_log->error("Did not receive SGW S1-U F-TEID in create session response\n"); return; } - m_mme_gtpc_log->console("Create Session Response -- SPGW control TEID %d\n", sgw_ctrl_fteid.teid); - m_mme_gtpc_log->info("Create Session Response -- SPGW control TEID %d\n", sgw_ctrl_fteid.teid); + m_mme_gtpc_log->console("Create Session Response -- SPGW control TEID %d\n", sgw_ctr_fteid.teid); + m_mme_gtpc_log->info("Create Session Response -- SPGW control TEID %d\n", sgw_ctr_fteid.teid); in_addr s1u_addr; s1u_addr.s_addr = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.ipv4; m_mme_gtpc_log->console("Create Session Response -- SPGW S1-U Address: %s\n", inet_ntoa(s1u_addr)); @@ -208,23 +214,33 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pac } //Save create session response info to E-RAB context - ue_ecm_ctx_t *ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_s1ap_id); - if(ecm_ctx ==NULL){ + ue_emm_ctx_t *emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(imsi); + if(emm_ctx == NULL){ + m_mme_gtpc_log->error("Could not find UE EMM context\n"); + return; + } + ue_ecm_ctx_t *ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(emm_ctx->mme_ue_s1ap_id); + if(ecm_ctx == NULL){ m_mme_gtpc_log->error("Could not find UE ECM context\n"); return; } - ue_emm_ctx_t *emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ecm_ctx->imsi); - if(emm_ctx ==NULL){ - m_mme_gtpc_log->error("Could not find UE EMM context\n"); + + //Save SGW ctrl F-TEID in GTP-C context + std::map::iterator it_g = m_imsi_to_gtpc_ctx.find(imsi); + if(it_g == m_imsi_to_gtpc_ctx.end()) + { + //Could not find GTP-C Context + m_mme_gtpc_log->error("Could not find GTP-C context\n"); return; } + gtpc_ctx_t *gtpc_ctx = &it_g->second; + gtpc_ctx->sgw_ctr_fteid = sgw_ctr_fteid; //Set EPS bearer context //FIXME default EPS bearer is hard-coded int default_bearer=5; erab_ctx_t *erab_ctx = &ecm_ctx->erabs_ctx[default_bearer]; erab_ctx->pdn_addr_alloc= cs_resp->paa; - erab_ctx->sgw_ctrl_fteid = sgw_ctrl_fteid; erab_ctx->sgw_s1u_fteid = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid; m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, erab_ctx, pack_attach); @@ -232,16 +248,23 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pac void -mme_gtpc::send_modify_bearer_request(erab_ctx_t *erab_ctx) +mme_gtpc::send_modify_bearer_request(uint64_t imsi, erab_ctx_t *erab_ctx) { m_mme_gtpc_log->info("Sending GTP-C Modify bearer request\n"); srslte::gtpc_pdu mb_req_pdu; - srslte::gtpc_f_teid_ie *enb_fteid = &erab_ctx->enb_fteid; - srslte::gtpc_f_teid_ie *sgw_ctrl_fteid = &erab_ctx->sgw_ctrl_fteid; + srslte::gtp_fteid_t *enb_fteid = &erab_ctx->enb_fteid; + + std::map::iterator it = m_imsi_to_gtpc_ctx.find(imsi); + if(it == m_imsi_to_gtpc_ctx.end()) + { + m_mme_gtpc_log->error("Modify bearer request for UE without GTP-C connection\n"); + return; + } + srslte::gtp_fteid_t sgw_ctr_fteid = it->second.sgw_ctr_fteid; srslte::gtpc_header *header = &mb_req_pdu.header; header->teid_present = true; - header->teid = sgw_ctrl_fteid->teid; + header->teid = sgw_ctr_fteid.teid; header->type = srslte::GTPC_MSG_TYPE_MODIFY_BEARER_REQUEST; srslte::gtpc_modify_bearer_request *mb_req = &mb_req_pdu.choice.modify_bearer_request; @@ -249,7 +272,7 @@ mme_gtpc::send_modify_bearer_request(erab_ctx_t *erab_ctx) mb_req->eps_bearer_context_to_modify.s1_u_enb_f_teid.ipv4 = enb_fteid->ipv4; mb_req->eps_bearer_context_to_modify.s1_u_enb_f_teid.teid = enb_fteid->teid; - m_mme_gtpc_log->info("GTP-C Modify bearer request -- S-GW Control TEID %d\n", sgw_ctrl_fteid->teid ); + m_mme_gtpc_log->info("GTP-C Modify bearer request -- S-GW Control TEID %d\n", sgw_ctr_fteid.teid ); struct in_addr addr; addr.s_addr = enb_fteid->ipv4; m_mme_gtpc_log->info("GTP-C Modify bearer request -- S1-U TEID 0x%x, IP %s\n", enb_fteid->teid, inet_ntoa(addr) ); diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 83b5c9594..02a2fb8d2 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -246,7 +246,7 @@ s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_I } if(send_modify) { - m_mme_gtpc->send_modify_bearer_request(&ue_ecm_ctx->erabs_ctx[5]); + m_mme_gtpc->send_modify_bearer_request(ue_ecm_ctx->imsi, &ue_ecm_ctx->erabs_ctx[5]); } send_modify = true; return true; diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index d897d3b2e..11eb2b9af 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -861,7 +861,7 @@ s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, u m_s1ap_log->error("EPS Bearer ID out of range\n"); return false; } - m_mme_gtpc->send_modify_bearer_request(&ue_ecm_ctx->erabs_ctx[act_bearer.eps_bearer_id]); + m_mme_gtpc->send_modify_bearer_request(ue_ecm_ctx->imsi, &ue_ecm_ctx->erabs_ctx[act_bearer.eps_bearer_id]); //Send reply to eNB m_s1ap_log->console("Packing EMM infromationi\n"); From a3b31966b88c899e63776f886bd50d2d4320d8fd Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 7 Mar 2018 18:48:08 +0000 Subject: [PATCH 067/143] Changing Activate EPS bearer function to work with IMSI. --- srsepc/hdr/mme/s1ap.h | 2 +- srsepc/src/mme/mme_gtpc.cc | 8 ++++---- srsepc/src/mme/s1ap.cc | 22 +++++++++++++++------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 3f9f035e0..311a65784 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -72,7 +72,7 @@ public: bool handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri); bool handle_successful_outcome(LIBLTE_S1AP_SUCCESSFULOUTCOME_STRUCT *msg); - void activate_eps_bearer(uint32_t mme_s1ap_id, uint8_t ebi); + void activate_eps_bearer(uint64_t imsi, uint8_t ebi); void print_enb_ctx_info(const std::string &prefix, const enb_ctx_t &enb_ctx); diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index fff721978..ff603e14d 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -288,16 +288,16 @@ void mme_gtpc::handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu) { uint32_t mme_ctrl_teid = mb_resp_pdu->header.teid; - std::map::iterator mme_s1ap_id_it = m_teid_to_mme_s1ap_id.find(mme_ctrl_teid); - if(mme_s1ap_id_it == m_teid_to_mme_s1ap_id.end()) + std::map::iterator imsi_it = m_mme_ctr_teid_to_imsi.find(mme_ctrl_teid); + if(imsi_it == m_mme_ctr_teid_to_imsi.end()) { - m_mme_gtpc_log->error("Could not find MME S1AP Id from control TEID\n"); + m_mme_gtpc_log->error("Could not find IMSI from control TEID\n"); return; } uint8_t ebi = mb_resp_pdu->choice.modify_bearer_response.eps_bearer_context_modified.ebi; m_mme_gtpc_log->debug("Activating EPS bearer with id %d\n", ebi); - m_s1ap->activate_eps_bearer(mme_s1ap_id_it->second,ebi); + m_s1ap->activate_eps_bearer(imsi_it->second,ebi); return; } diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 6e301b9ae..a54096114 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -501,23 +501,31 @@ s1ap::delete_ues_ecm_ctx_in_enb(uint16_t enb_id) //UE Bearer Managment void -s1ap::activate_eps_bearer(uint32_t mme_s1ap_id, uint8_t ebi) +s1ap::activate_eps_bearer(uint64_t imsi, uint8_t ebi) { - std::map::iterator ue_ctx_it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_s1ap_id); - if(ue_ctx_it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) + std::map::iterator emm_ctx_it = m_imsi_to_ue_emm_ctx.find(imsi); + if(emm_ctx_it == m_imsi_to_ue_emm_ctx.end()) { - m_s1ap_log->error("Could not find UE context\n"); + m_s1ap_log->error("Could not find UE EMM context\n"); + return; + } + uint32_t mme_ue_s1ap_id = emm_ctx_it->second->mme_ue_s1ap_id; + std::map::iterator ecm_ctx_it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_s1ap_id); + if(ecm_ctx_it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) + { + m_s1ap_log->error("Could not find UE ECM context\n"); return; } - ue_ecm_ctx_t * ue_ctx = ue_ctx_it->second; - if (ue_ctx->erabs_ctx[ebi].state != ERAB_CTX_SETUP) + + ue_ecm_ctx_t * ecm_ctx = ue_ctx_it->second; + if (ecm_ctx->erabs_ctx[ebi].state != ERAB_CTX_SETUP) { m_s1ap_log->error("EPS Bearer could not be activated. MME S1AP Id %d, EPS Bearer id %d, state %d\n",mme_s1ap_id,ebi,ue_ctx->erabs_ctx[ebi].state); m_s1ap_log->console("EPS Bearer could not be activated. MME S1AP Id %d, EPS Bearer id %d\n",mme_s1ap_id,ebi,ue_ctx->erabs_ctx[ebi].state); return; } - ue_ctx->erabs_ctx[ebi].state = ERAB_ACTIVE; + ecm_ctx->erabs_ctx[ebi].state = ERAB_ACTIVE; m_s1ap_log->info("Activated EPS Bearer\n"); return; } From ef4ad0aa20bf913a2132cb3537ed88d9698c830d Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 7 Mar 2018 19:15:32 +0000 Subject: [PATCH 068/143] Starting to change delete session request. --- srsepc/src/mme/mme_gtpc.cc | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index ff603e14d..015ce5093 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -303,25 +303,13 @@ mme_gtpc::handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu) } void -mme_gtpc::send_delete_session_request(ue_ecm_ctx_t *ue_ecm_ctx) +mme_gtpc::send_delete_session_request(uint64_t imsi) { - m_mme_gtpc_log->info("Sending GTP-C Delete Session Request request\n"); + m_mme_gtpc_log->info("Sending GTP-C Delete Session Request request. IMSI %d\n",imsi); srslte::gtpc_pdu del_req_pdu; - srslte::gtpc_f_teid_ie *sgw_ctrl_fteid = NULL; - - //FIXME the UE control TEID sould be stored in the UE ctxt, not in the E-RAB ctxt - //Maybe a mme_s1ap_id to ctrl teid map as well? + srslte::gtp_fteid_t sgw_ctrl_fteid; - for(int i = 0; ierabs_ctx[i].state != ERAB_DEACTIVATED) - { - sgw_ctrl_fteid = &ue_ecm_ctx->erabs_ctx[i].sgw_ctrl_fteid; - break; - } - } - //FIXME: add proper error handling - assert(sgw_ctrl_fteid != NULL); + std::map::iterator it = m_imsi_to_gtpc_ctx.find(imsi); srslte::gtpc_header *header = &del_req_pdu.header; header->teid_present = true; From 3b338067c90dcff0841326043c5628aa3b9afd30 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 8 Mar 2018 12:13:53 +0000 Subject: [PATCH 069/143] Changing Delete session request to delete GTP-C context. --- srsepc/hdr/mme/mme_gtpc.h | 2 +- srsepc/src/mme/mme_gtpc.cc | 33 +++++++++++++++++++++------ srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 2 +- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index f94b05ccd..b832969ee 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -56,7 +56,7 @@ public: void handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pack_attach); void send_modify_bearer_request(uint64_t imsi, erab_ctx_t *bearer_ctx); void handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu); - void send_delete_session_request(ue_ecm_ctx_t *ue_ecm_ctx); + void send_delete_session_request(uint64_t imsi); private: diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 015ce5093..eec12d9ac 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -307,28 +307,47 @@ mme_gtpc::send_delete_session_request(uint64_t imsi) { m_mme_gtpc_log->info("Sending GTP-C Delete Session Request request. IMSI %d\n",imsi); srslte::gtpc_pdu del_req_pdu; - srslte::gtp_fteid_t sgw_ctrl_fteid; - - std::map::iterator it = m_imsi_to_gtpc_ctx.find(imsi); - + srslte::gtp_fteid_t sgw_ctr_fteid; + srslte::gtp_fteid_t mme_ctr_fteid; + //Get S-GW Ctr TEID + std::map::iterator it_ctx = m_imsi_to_gtpc_ctx.find(imsi); + if(it_ctx == m_imsi_to_gtpc_ctx.end()) + { + m_mme_gtpc_log->error("Could not find GTP-C context to remove\n"); + return; + } + sgw_ctr_fteid = it_ctx->second.sgw_ctr_fteid; + mme_ctr_fteid = it_ctx->second.mme_ctr_fteid; srslte::gtpc_header *header = &del_req_pdu.header; header->teid_present = true; - header->teid = sgw_ctrl_fteid->teid; + header->teid = sgw_ctr_fteid.teid; header->type = srslte::GTPC_MSG_TYPE_DELETE_SESSION_REQUEST; srslte::gtpc_delete_session_request *del_req = &del_req_pdu.choice.delete_session_request; del_req->cause.cause_value = srslte::GTPC_CAUSE_VALUE_ISR_DEACTIVATION; - m_mme_gtpc_log->info("GTP-C Delete Session Request -- S-GW Control TEID %d\n", sgw_ctrl_fteid->teid ); + m_mme_gtpc_log->info("GTP-C Delete Session Request -- S-GW Control TEID %d\n", sgw_ctr_fteid.teid ); srslte::gtpc_pdu del_resp_pdu; m_spgw->handle_delete_session_request(&del_req_pdu, &del_resp_pdu); //TODO Handle delete session response + + //Delete GTP-C context + std::map::iterator it_imsi = m_mme_ctr_teid_to_imsi.find(mme_ctr_fteid.teid); + if(it_imsi == m_mme_ctr_teid_to_imsi.end()) + { + m_mme_gtpc_log->error("Could not find IMSI from MME ctr TEID"); + } + else + { + m_mme_ctr_teid_to_imsi.erase(it_imsi); + } + m_imsi_to_gtpc_ctx.erase(it_ctx); return; } void -mme_gtpc::send_release_access_bearers_request(ue_ecm_ctx_t *ecm_ctx) +mme_gtpc::send_release_access_bearers_request(uint64_t imsi) { m_mme_gtpc_log->info("Sending GTP-C Delete Access Bearers Request\n"); srslte::gtpc_pdu rel_req_pdu; diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 02a2fb8d2..dd211cb04 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -283,7 +283,7 @@ s1ap_ctx_mngmt_proc::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECON if(active == true) { //There are active E-RABs, send delete session request - m_mme_gtpc->send_delete_session_request(ue_ecm_ctx); + m_mme_gtpc->send_delete_session_request(ue_ecm_ctx->imsi); } //m_s1ap->delete_ue_ctx(ue_ctx); for(int i=0;i Date: Thu, 8 Mar 2018 12:50:07 +0000 Subject: [PATCH 070/143] Adding release access bearers request. --- lib/include/srslte/asn1/gtpc.h | 33 +++++++++++++----------------- lib/include/srslte/asn1/gtpc_msg.h | 31 ++++++++++++++++++++++++++++ srsepc/hdr/mme/mme_gtpc.h | 1 + srsepc/src/mme/mme_gtpc.cc | 11 +++------- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/lib/include/srslte/asn1/gtpc.h b/lib/include/srslte/asn1/gtpc.h index aca57a4bf..d204cd31d 100644 --- a/lib/include/srslte/asn1/gtpc.h +++ b/lib/include/srslte/asn1/gtpc.h @@ -52,16 +52,15 @@ const uint8_t GTPC_V2 = 2; * n+2 | Sequence | * n+3 | Spare | ***************************************************************************/ - - typedef struct gtpc_header - { - uint8_t version; - bool piggyback; - bool teid_present; - uint8_t type; - uint64_t teid; - uint64_t sequence; - } gtpc_header_t; +typedef struct gtpc_header +{ + uint8_t version; + bool piggyback; + bool teid_present; + uint8_t type; + uint64_t teid; + uint64_t sequence; +}gtpc_header_t; /**************************************************************************** * GTP-C v2 Payload @@ -69,16 +68,17 @@ const uint8_t GTPC_V2 = 2; * * Union that hold the different structures for the possible message types. ***************************************************************************/ - typedef union gtpc_msg_choice { struct gtpc_create_session_request create_session_request; struct gtpc_create_session_response create_session_response; struct gtpc_modify_bearer_request modify_bearer_request; struct gtpc_modify_bearer_response modify_bearer_response; + struct gtpc_release_access_bearers_request release_access_bearers_request; + struct gtpc_release_access_bearers_response release_access_bearers_response; struct gtpc_delete_session_request delete_session_request; struct gtpc_delete_session_response delete_session_response; -} gtpc_msg_choice_t; +}gtpc_msg_choice_t; /**************************************************************************** * GTP-C v2 Message @@ -88,15 +88,10 @@ typedef union gtpc_msg_choice * of one GTP-C header and one union of structures, which can hold * all the possible GTP-C messages ***************************************************************************/ - typedef struct gtpc_pdu { struct gtpc_header header; union gtpc_msg_choice choice; -} gtpc_pdu_t; - - - -}; - +}gtpc_pdu_t; +}//namespace #endif diff --git a/lib/include/srslte/asn1/gtpc_msg.h b/lib/include/srslte/asn1/gtpc_msg.h index 4271b064d..159be0c80 100644 --- a/lib/include/srslte/asn1/gtpc_msg.h +++ b/lib/include/srslte/asn1/gtpc_msg.h @@ -410,5 +410,36 @@ struct gtpc_delete_session_response //Private extension }; +/**************************************************************************** + * + * GTP-C v2 Release Access Bearers Request + * Ref: 3GPP TS 29.274 v10.14.0 Table 7.2.21.1-1 + * + ***************************************************************************/ +struct gtpc_release_access_bearers_request +{ + bool list_of_rabs_present; + //Linked EPS Bearer ID + bool originating_node_present; + //Indication Flags + //Private Extension +}; + + /**************************************************************************** + * + * GTP-C v2 Delete Session Response + * Ref: 3GPP TS 29.274 v10.14.0 Table 7.2.22.1-1 + * + ***************************************************************************/ + + struct gtpc_release_access_bearers_response + { + struct gtpc_cause_ie cause; + //Recovery + //Private extension + }; + + + } //namespace #endif //GTPC_V2_MSG_H diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index b832969ee..6e3ab76b1 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -56,6 +56,7 @@ public: void handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pack_attach); void send_modify_bearer_request(uint64_t imsi, erab_ctx_t *bearer_ctx); void handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu); + void send_release_access_bearers_request(uint64_t imsi); void send_delete_session_request(uint64_t imsi); private: diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index eec12d9ac..6a6ffda5c 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -351,10 +351,6 @@ mme_gtpc::send_release_access_bearers_request(uint64_t imsi) { m_mme_gtpc_log->info("Sending GTP-C Delete Access Bearers Request\n"); srslte::gtpc_pdu rel_req_pdu; - if(ecm_ctx->state != ECM_STATE_CONNECTED ) - { - m_mme_gtpc_log->error("ECM State is not connected. No valid SGW Ctr TEID present\n"); - } srslte::gtpc_f_teid_ie *sgw_ctrl_fteid = NULL; srslte::gtpc_header *header = &rel_req_pdu.header; @@ -363,13 +359,12 @@ mme_gtpc::send_release_access_bearers_request(uint64_t imsi) header->type = srslte::GTPC_MSG_TYPE_RELEASE_ACCESS_BEARERS_REQUEST; srslte::gtpc_release_access_bearers_request *rel_req = &rel_req_pdu.choice.release_access_bearers_request; - del_req->cause.cause_value = srslte::GTPC_CAUSE_VALUE_ISR_DEACTIVATION; m_mme_gtpc_log->info("GTP-C Release Access Berarers Request -- S-GW Control TEID %d\n", sgw_ctrl_fteid->teid ); - srslte::gtpc_pdu del_resp_pdu; - m_spgw->handle_delete_session_request(&del_req_pdu, &del_resp_pdu); + srslte::gtpc_pdu rel_resp_pdu; + m_spgw->handle_release_access_bearers_response(&del_req_pdu, &rel_resp_pdu); - //TODO Handle delete session response + //The GTP-C connection will not be torn down, just the user plane bearers. return; } } //namespace srsepc From 2b84e7838978784247c6547d7e82baebb44a94ed Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 8 Mar 2018 14:19:13 +0000 Subject: [PATCH 071/143] Adding release access bearer request to SPGW. Compiling now. --- srsepc/hdr/spgw/spgw.h | 1 + srsepc/src/mme/mme_gtpc.cc | 2 +- srsepc/src/mme/s1ap.cc | 8 ++++---- srsepc/src/spgw/spgw.cc | 29 ++++++++++++++++++++++++++++- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/srsepc/hdr/spgw/spgw.h b/srsepc/hdr/spgw/spgw.h index 3837dcf08..14868c571 100644 --- a/srsepc/hdr/spgw/spgw.h +++ b/srsepc/hdr/spgw/spgw.h @@ -76,6 +76,7 @@ public: void handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu,bool pack_attach); void handle_modify_bearer_request(struct srslte::gtpc_pdu *mb_req_pdu, struct srslte::gtpc_pdu *mb_resp_pdu); void handle_delete_session_request(struct srslte::gtpc_pdu *del_req_pdu, struct srslte::gtpc_pdu *del_resp_pdu); + void handle_release_access_bearers_request(struct srslte::gtpc_pdu *rel_req_pdu, struct srslte::gtpc_pdu *rel_resp_pdu); void handle_sgi_pdu(srslte::byte_buffer_t *msg); void handle_s1u_pdu(srslte::byte_buffer_t *msg); diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 6a6ffda5c..608b29b6e 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -362,7 +362,7 @@ mme_gtpc::send_release_access_bearers_request(uint64_t imsi) m_mme_gtpc_log->info("GTP-C Release Access Berarers Request -- S-GW Control TEID %d\n", sgw_ctrl_fteid->teid ); srslte::gtpc_pdu rel_resp_pdu; - m_spgw->handle_release_access_bearers_response(&del_req_pdu, &rel_resp_pdu); + m_spgw->handle_release_access_bearers_request(&rel_req_pdu, &rel_resp_pdu); //The GTP-C connection will not be torn down, just the user plane bearers. return; diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index a54096114..19b32ba24 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -510,18 +510,18 @@ s1ap::activate_eps_bearer(uint64_t imsi, uint8_t ebi) return; } uint32_t mme_ue_s1ap_id = emm_ctx_it->second->mme_ue_s1ap_id; - std::map::iterator ecm_ctx_it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_s1ap_id); + std::map::iterator ecm_ctx_it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_ue_s1ap_id); if(ecm_ctx_it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) { m_s1ap_log->error("Could not find UE ECM context\n"); return; } - ue_ecm_ctx_t * ecm_ctx = ue_ctx_it->second; + ue_ecm_ctx_t * ecm_ctx = ecm_ctx_it->second; if (ecm_ctx->erabs_ctx[ebi].state != ERAB_CTX_SETUP) { - m_s1ap_log->error("EPS Bearer could not be activated. MME S1AP Id %d, EPS Bearer id %d, state %d\n",mme_s1ap_id,ebi,ue_ctx->erabs_ctx[ebi].state); - m_s1ap_log->console("EPS Bearer could not be activated. MME S1AP Id %d, EPS Bearer id %d\n",mme_s1ap_id,ebi,ue_ctx->erabs_ctx[ebi].state); + m_s1ap_log->error("EPS Bearer could not be activated. MME S1AP Id %d, EPS Bearer id %d, state %d\n",mme_ue_s1ap_id,ebi,ecm_ctx->erabs_ctx[ebi].state); + m_s1ap_log->console("EPS Bearer could not be activated. MME S1AP Id %d, EPS Bearer id %d\n",mme_ue_s1ap_id,ebi,ecm_ctx->erabs_ctx[ebi].state); return; } diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index df62fa43b..b16b89c27 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -571,7 +571,7 @@ spgw::handle_delete_session_request(struct srslte::gtpc_pdu *del_req_pdu, struct //Delete data tunnel pthread_mutex_lock(&m_mutex); - std::map::iterator data_it = m_ip_to_teid.find(tunnel_ctx->ue_ipv4); + std::map::iterator data_it = m_ip_to_teid.find(tunnel_ctx->ue_ipv4); if(data_it != m_ip_to_teid.end()) { m_ip_to_teid.erase(data_it); @@ -583,4 +583,31 @@ spgw::handle_delete_session_request(struct srslte::gtpc_pdu *del_req_pdu, struct return; } +void +spgw::handle_release_access_bearers_request(struct srslte::gtpc_pdu *rel_req_pdu, struct srslte::gtpc_pdu *rel_resp_pdu) +{ + //Find tunel ctxt + uint32_t ctrl_teid = rel_req_pdu->header.teid; + std::map::iterator tunnel_it = m_teid_to_tunnel_ctx.find(ctrl_teid); + if(tunnel_it == m_teid_to_tunnel_ctx.end()) + { + m_spgw_log->warning("Could not find TEID %d to release bearers from\n",ctrl_teid); + return; + } + spgw_tunnel_ctx_t *tunnel_ctx = tunnel_it->second; + in_addr_t ue_ipv4 = tunnel_ctx->ue_ipv4; + + //Delete data tunnel + pthread_mutex_lock(&m_mutex); + std::map::iterator data_it = m_ip_to_teid.find(tunnel_ctx->ue_ipv4); + if(data_it != m_ip_to_teid.end()) + { + m_ip_to_teid.erase(data_it); + } + pthread_mutex_unlock(&m_mutex); + + //Do NOT delete control tunnel + return; +} + } //namespace srsepc From 6583d6b2e5713eeb94fa62bbb1026bb08adb208f Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 8 Mar 2018 15:55:53 +0000 Subject: [PATCH 072/143] Changing handle UE context release to send release access bearer request instead od delte session request. --- srsepc/hdr/mme/s1ap_common.h | 2 +- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 34 ++++++++++++--------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index 15f4e3c6d..4cda8376f 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -146,7 +146,7 @@ typedef struct{ uint32_t enb_ue_s1ap_id; uint32_t mme_ue_s1ap_id; struct sctp_sndrcvinfo enb_sri; - ecm_state_t ecm_state; + ecm_state_t state; srslte::gtpc_f_teid_ie sgw_ctrl_fteid; erab_ctx_t erabs_ctx[MAX_ERABS_PER_UE]; bool eit; diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index dd211cb04..672332868 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -262,38 +262,34 @@ s1ap_ctx_mngmt_proc::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECON m_s1ap_log->info("Received UE Context Release Request. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); m_s1ap_log->console("Received UE Context Release Request. MME-UE S1AP Id %d\n", mme_ue_s1ap_id); - ue_ecm_ctx_t *ue_ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); - if(ue_ecm_ctx == NULL) + ue_ecm_ctx_t *ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); + if(ecm_ctx == NULL) { - m_s1ap_log->info("UE not found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + m_s1ap_log->info("No UE ECM context to release found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + m_s1ap_log->console("No UE ECM context to release found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); return false; } - //Delete any context at the SPGW - bool active = false; - for(int i=0;istate == ECM_STATE_CONNECTED) { - if(ue_ecm_ctx->erabs_ctx[i].state != ERAB_DEACTIVATED) //FIXME use ECM state - { - active = true; - //ue_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; - break; - } + //There are active E-RABs, send release access mearers request + m_mme_gtpc->send_release_access_bearers_request(ecm_ctx->imsi); } - if(active == true) + else { - //There are active E-RABs, send delete session request - m_mme_gtpc->send_delete_session_request(ue_ecm_ctx->imsi); + //No ECM Context to release + m_s1ap_log->info("UE is not ECM connected. No need to release S1-U. MME UE S1AP Id %d\n", mme_ue_s1ap_id); + m_s1ap_log->console("UE is not ECM connected. No need to release S1-U. MME UE S1AP Id %d\n", mme_ue_s1ap_id); } //m_s1ap->delete_ue_ctx(ue_ctx); for(int i=0;ierabs_ctx[i].state = ERAB_DEACTIVATED; + ecm_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; } //Delete UE context - m_s1ap->delete_ue_ecm_ctx(ue_ecm_ctx->mme_ue_s1ap_id); - - m_s1ap_log->info("Deleted UE Context.\n"); + m_s1ap->delete_ue_ecm_ctx(ecm_ctx->mme_ue_s1ap_id); + m_s1ap_log->info("Deleted UE ECM Context.\n"); return true; } From de936b30d1ec54b2e79a45a1835616adf66a3ae7 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 8 Mar 2018 16:17:13 +0000 Subject: [PATCH 073/143] Fixed small bug in send create session request. --- srsepc/src/mme/mme_gtpc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 608b29b6e..799bd8bfd 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -125,7 +125,7 @@ mme_gtpc::send_create_session_request(uint64_t imsi, bool pack_attach) //Check whether this UE is already registed std::map::iterator it = m_imsi_to_gtpc_ctx.find(imsi); - if(it == m_imsi_to_gtpc_ctx.end()) + if(it != m_imsi_to_gtpc_ctx.end()) { m_mme_gtpc_log->warning("Create Session Request being called for an UE with an active GTP-C connection.\n"); m_mme_gtpc_log->warning("Deleting previous GTP-C connection.\n"); From 9b28527423df2267411f13af9ca6dd2747292c88 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 8 Mar 2018 17:59:03 +0000 Subject: [PATCH 074/143] Fixed bug in release access bearers request --- srsepc/src/mme/mme_gtpc.cc | 16 +++++++++++++--- srsepc/src/mme/s1ap.cc | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 799bd8bfd..a4b3bbbe3 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -351,15 +351,25 @@ mme_gtpc::send_release_access_bearers_request(uint64_t imsi) { m_mme_gtpc_log->info("Sending GTP-C Delete Access Bearers Request\n"); srslte::gtpc_pdu rel_req_pdu; - srslte::gtpc_f_teid_ie *sgw_ctrl_fteid = NULL; + srslte::gtp_fteid_t sgw_ctr_fteid; + + //Get S-GW Ctr TEID + std::map::iterator it_ctx = m_imsi_to_gtpc_ctx.find(imsi); + if(it_ctx == m_imsi_to_gtpc_ctx.end()) + { + m_mme_gtpc_log->error("Could not find GTP-C context to remove\n"); + return; + } + sgw_ctr_fteid = it_ctx->second.sgw_ctr_fteid; + //Set GTP-C header srslte::gtpc_header *header = &rel_req_pdu.header; header->teid_present = true; - header->teid = sgw_ctrl_fteid->teid; + header->teid = sgw_ctr_fteid.teid; header->type = srslte::GTPC_MSG_TYPE_RELEASE_ACCESS_BEARERS_REQUEST; srslte::gtpc_release_access_bearers_request *rel_req = &rel_req_pdu.choice.release_access_bearers_request; - m_mme_gtpc_log->info("GTP-C Release Access Berarers Request -- S-GW Control TEID %d\n", sgw_ctrl_fteid->teid ); + m_mme_gtpc_log->info("GTP-C Release Access Berarers Request -- S-GW Control TEID %d\n", sgw_ctr_fteid.teid ); srslte::gtpc_pdu rel_resp_pdu; m_spgw->handle_release_access_bearers_request(&rel_req_pdu, &rel_resp_pdu); diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 19b32ba24..9d3c9e042 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -526,6 +526,7 @@ s1ap::activate_eps_bearer(uint64_t imsi, uint8_t ebi) } ecm_ctx->erabs_ctx[ebi].state = ERAB_ACTIVE; + ecm_ctx->state = ECM_STATE_CONNECTED; m_s1ap_log->info("Activated EPS Bearer\n"); return; } From d5478ff7a2b4b72e4cfdc3a9e63089d160053100 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 9 Mar 2018 16:25:59 +0000 Subject: [PATCH 075/143] Starting to use EMM state to know whether attach request or service request are initiating the NAS. --- srsepc/hdr/mme/mme_gtpc.h | 4 +- srsepc/hdr/mme/s1ap_common.h | 5 +- srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h | 2 +- srsepc/hdr/spgw/spgw.h | 2 +- srsepc/src/mme/mme_gtpc.cc | 9 ++-- srsepc/src/mme/s1ap.cc | 9 +++- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 9 ++-- srsepc/src/mme/s1ap_nas_transport.cc | 75 +++++++++++++++------------ srsepc/src/spgw/spgw.cc | 8 +-- 9 files changed, 71 insertions(+), 52 deletions(-) diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index 6e3ab76b1..23e6acf0a 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -52,8 +52,8 @@ public: bool init(srslte::log_filter *mme_gtpc_log); uint32_t get_new_ctrl_teid(); - void send_create_session_request(uint64_t imsi, bool pack_attach); - void handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pack_attach); + void send_create_session_request(uint64_t imsi); + void handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu); void send_modify_bearer_request(uint64_t imsi, erab_ctx_t *bearer_ctx); void handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu); void send_release_access_bearers_request(uint64_t imsi); diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index 4cda8376f..7ffaf3434 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -136,9 +136,12 @@ typedef struct{ LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT guti; eps_security_ctx_t security_ctxt; uint8_t procedure_transaction_id; - emm_state_t emm_state; + emm_state_t state; uint32_t mme_ue_s1ap_id; uint8_t attach_type; + //enum nas_init_msg init_msg; + //enum emm_connection_management conn_mngmnt_state; + //enum emm_common_proc common_proc_state; } ue_emm_ctx_t; typedef struct{ diff --git a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h index 1886b9d50..44458aea6 100644 --- a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h @@ -48,7 +48,7 @@ public: void init(void); //bool send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, struct srslte::gtpc_create_session_response *cs_resp, struct srslte::gtpc_f_teid_ie sgw_ctrl_fteid); - bool send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, ue_ecm_ctx_t *ecm_ctx, erab_ctx_t *erab_ctx, bool pack_attach); + bool send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, ue_ecm_ctx_t *ecm_ctx, erab_ctx_t *erab_ctx); bool handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT *in_ctxt_resp); bool handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT *ue_rel, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool send_ue_context_release_command(ue_ecm_ctx_t *ecm_ctx, srslte::byte_buffer_t *reply_buffer); diff --git a/srsepc/hdr/spgw/spgw.h b/srsepc/hdr/spgw/spgw.h index 14868c571..c68626f9c 100644 --- a/srsepc/hdr/spgw/spgw.h +++ b/srsepc/hdr/spgw/spgw.h @@ -73,7 +73,7 @@ public: void stop(); void run_thread(); - void handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu,bool pack_attach); + void handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu); void handle_modify_bearer_request(struct srslte::gtpc_pdu *mb_req_pdu, struct srslte::gtpc_pdu *mb_resp_pdu); void handle_delete_session_request(struct srslte::gtpc_pdu *del_req_pdu, struct srslte::gtpc_pdu *del_resp_pdu); void handle_release_access_bearers_request(struct srslte::gtpc_pdu *rel_req_pdu, struct srslte::gtpc_pdu *rel_resp_pdu); diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index a4b3bbbe3..595166494 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -88,7 +88,7 @@ mme_gtpc::get_new_ctrl_teid() return m_next_ctrl_teid++; //FIXME Use a Id pool? } void -mme_gtpc::send_create_session_request(uint64_t imsi, bool pack_attach) +mme_gtpc::send_create_session_request(uint64_t imsi) { m_mme_gtpc_log->info("Sending Create Session Request.\n"); m_mme_gtpc_log->console("Sending Create Session Request.\n"); @@ -151,12 +151,12 @@ mme_gtpc::send_create_session_request(uint64_t imsi, bool pack_attach) bzero(>pc_ctx,sizeof(gtpc_ctx_t)); gtpc_ctx.mme_ctr_fteid = cs_req->sender_f_teid; m_imsi_to_gtpc_ctx.insert(std::pair(imsi,gtpc_ctx)); - m_spgw->handle_create_session_request(cs_req, &cs_resp_pdu, pack_attach); + m_spgw->handle_create_session_request(cs_req, &cs_resp_pdu); } void -mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pack_attach) +mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu) { struct srslte::gtpc_create_session_response *cs_resp = & cs_resp_pdu->choice.create_session_response; m_mme_gtpc_log->info("Received Create Session Response\n"); @@ -243,7 +243,8 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu, bool pac erab_ctx->pdn_addr_alloc= cs_resp->paa; erab_ctx->sgw_s1u_fteid = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid; - m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, erab_ctx, pack_attach); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, erab_ctx); + return; } diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 9d3c9e042..845675057 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -350,9 +350,16 @@ s1ap::delete_enb_ctx(int32_t assoc_id) void s1ap::add_new_ue_emm_ctx(const ue_emm_ctx_t &ue_emm_ctx) { + std::map::iterator emm_ctx_it = m_imsi_to_ue_emm_ctx.find(ue_emm_ctx.imsi); + if(emm_ctx_it != m_imsi_to_ue_emm_ctx.end()) + { + m_s1ap_log->warning("EMM Context already exists. Replacing EMM Context\n"); + delete emm_ctx_it->second; + m_imsi_to_ue_emm_ctx.erase(emm_ctx_it); + } + ue_emm_ctx_t *ue_ptr = new ue_emm_ctx_t; memcpy(ue_ptr,&ue_emm_ctx,sizeof(ue_emm_ctx)); - //This map will store UEs EMM context m_imsi_to_ue_emm_ctx.insert(std::pair(ue_ptr->imsi,ue_ptr)); } diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 672332868..a1ed611ee 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -79,8 +79,7 @@ s1ap_ctx_mngmt_proc::init(void) bool s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, ue_ecm_ctx_t *ecm_ctx, - erab_ctx_t *erab_ctx, - bool pack_attach) + erab_ctx_t *erab_ctx) { int s1mme = m_s1ap->get_s1_mme(); @@ -161,13 +160,13 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, m_s1ap_log->info_hex(emm_ctx->security_ctxt.k_enb, 32, "Initial Context Setup Request -- Key eNB\n"); srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); - if(pack_attach) + if(emm_ctx->state == EMM_STATE_DEREGISTERED) { - pack_attach = false; + //Attach procedure initiated from an attach request m_s1ap_nas_transport->pack_attach_accept(emm_ctx, ecm_ctx, erab_ctx_req, &erab_ctx->pdn_addr_alloc, nas_buffer); - } + LIBLTE_ERROR_ENUM err = liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)reply_buffer); if(err != LIBLTE_SUCCESS) { diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 11eb2b9af..75a53aa40 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -107,14 +107,15 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA m_s1ap_log->console("Received Service Request \n"); if(!init_ue->S_TMSI_present) { - m_s1ap_log->error("Service request -- S-TMSI not present\n "); + m_s1ap_log->error("Service request -- S-TMSI not present\n"); m_s1ap_log->console("Service request -- S-TMSI not present\n" ); + return false; } uint32_t *m_tmsi = (uint32_t*) &init_ue->S_TMSI.m_TMSI.buffer; uint32_t enb_ue_s1ap_id = init_ue->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID; - m_s1ap_log->info("Service request -- S-TMSI 0x%x\n ", ntohl(*m_tmsi)); + m_s1ap_log->info("Service request -- S-TMSI 0x%x\n", ntohl(*m_tmsi)); m_s1ap_log->console("Service request -- S-TMSI 0x%x\n", ntohl(*m_tmsi) ); - m_s1ap_log->info("Service request -- eNB UE S1AP Id %d\n ", enb_ue_s1ap_id); + m_s1ap_log->info("Service request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); m_s1ap_log->console("Service request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); handle_nas_service_request(ntohl(*m_tmsi), enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); return false; @@ -320,7 +321,7 @@ s1ap_nas_transport::handle_nas_attach_request(uint32_t enb_ue_s1ap_id, //Get attach type from attach request if(attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMSI) - { + { m_s1ap_log->console("Attach Request -- IMSI-style attach request\n"); m_s1ap_log->info("Attach Request -- IMSI-style attach request\n"); handle_nas_imsi_attach_request(enb_ue_s1ap_id, attach_req, pdn_con_req, reply_buffer, reply_flag, enb_sri); @@ -592,7 +593,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); //Create session request m_s1ap_log->console("GUTI Attach -- NAS Integrity OK."); - m_mme_gtpc->send_create_session_request(ue_emm_ctx->imsi,true); + m_mme_gtpc->send_create_session_request(ue_emm_ctx->imsi); *reply_flag = false; //No reply needed return true; } @@ -643,22 +644,22 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, return true; } - ue_emm_ctx_t *ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(it->second); - if(ue_emm_ctx == NULL) + ue_emm_ctx_t *emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(it->second); + if(emm_ctx == NULL || emm_ctx->state != EMM_STATE_REGISTERED) { - m_s1ap_log->console("Could not find UE security context\n"); - m_s1ap_log->error("Could not find UE security context\n"); + m_s1ap_log->console("UE is not EMM-Registered.\n"); + m_s1ap_log->error("UE is not EMM-Registered.\n"); pack_service_reject(reply_buffer, LIBLTE_MME_EMM_CAUSE_IMPLICITLY_DETACHED, enb_ue_s1ap_id); *reply_flag = true; return true; } - ue_emm_ctx->security_ctxt.ul_nas_count++; - mac_valid = short_integrity_check(ue_emm_ctx,nas_msg); + emm_ctx->security_ctxt.ul_nas_count++; + mac_valid = short_integrity_check(emm_ctx,nas_msg); if(mac_valid) { m_s1ap_log->console("Service Request -- Short MAC valid\n"); m_s1ap_log->info("Service Request -- Short MAC valid\n"); - ue_ecm_ctx_t *ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(ue_emm_ctx->mme_ue_s1ap_id); + ue_ecm_ctx_t *ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(emm_ctx->mme_ue_s1ap_id); if(ecm_ctx !=NULL) { //Service request to Connected UE. @@ -672,7 +673,7 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, m_s1ap_log->info("Service Request -- User has ECM context already\n"); //m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); int default_bearer_id = 5; - m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(ue_emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[default_bearer_id],false); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[default_bearer_id]); } else { @@ -683,9 +684,9 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, m_s1ap_log->console("Service Request -- User without ECM context\n"); m_s1ap_log->info("Service Request -- User without ECM context\n"); //Create ECM context - ue_ecm_ctx.imsi = ue_emm_ctx->imsi; + ue_ecm_ctx.imsi = emm_ctx->imsi; ue_ecm_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); - ue_emm_ctx->mme_ue_s1ap_id = ue_ecm_ctx.mme_ue_s1ap_id; + emm_ctx->mme_ue_s1ap_id = ue_ecm_ctx.mme_ue_s1ap_id; //Set eNB information ue_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; memcpy(&ue_ecm_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); @@ -703,12 +704,11 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); //Re-generate K_eNB - liblte_security_generate_k_enb(ue_emm_ctx->security_ctxt.k_asme, ue_emm_ctx->security_ctxt.ul_nas_count, ue_emm_ctx->security_ctxt.k_enb); - m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",ue_emm_ctx->security_ctxt.ul_nas_count); + liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); + m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); //FIXME Send Modify context request OR send ctx release command and wait for the reply. - m_mme_gtpc->send_create_session_request(ue_ecm_ctx.imsi,false); + m_mme_gtpc->send_create_session_request(ue_ecm_ctx.imsi); m_s1ap_log->console("UE ESM Ctr TEID %d\n", ue_ecm_ctx.sgw_ctrl_fteid.teid); - // m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(ue_); } } else @@ -823,14 +823,14 @@ s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas { //FIXME The packging of GTP-C messages is not ready. //This means that GTP-U tunnels are created with function calls, as opposed to GTP-C. - m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi,true); + m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi); *reply_flag = false; //No reply needed } return true; } bool -s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) +s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { LIBLTE_MME_ATTACH_COMPLETE_MSG_STRUCT attach_comp; @@ -853,7 +853,13 @@ s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, u return false; } - m_s1ap_log->console("Unpacked Attached Complete Message\n"); + ue_emm_ctx_t *emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ecm_ctx->imsi); + if(emm_ctx == NULL) + { + m_s1ap_log->error("Received Attach complete, but could not find UE's EMM Context.\n"); + } + + m_s1ap_log->console("Unpacked Attached Complete Message. IMSI %d\n", emm_ctx->imsi); m_s1ap_log->console("Unpacked Activate Default EPS Bearer message. EPS Bearer id %d\n",act_bearer.eps_bearer_id); //ue_ctx->erabs_ctx[act_bearer->eps_bearer_id].enb_fteid; if(act_bearer.eps_bearer_id < 5 || act_bearer.eps_bearer_id > 15) @@ -861,14 +867,17 @@ s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, u m_s1ap_log->error("EPS Bearer ID out of range\n"); return false; } - m_mme_gtpc->send_modify_bearer_request(ue_ecm_ctx->imsi, &ue_ecm_ctx->erabs_ctx[act_bearer.eps_bearer_id]); - - //Send reply to eNB - m_s1ap_log->console("Packing EMM infromationi\n"); - *reply_flag = pack_emm_information(ue_ecm_ctx, reply_msg); - m_s1ap_log->console("Sending EMM infromation, bytes %d\n",reply_msg->N_bytes); - m_s1ap_log->info("Sending EMM infromation\n"); - + if(emm_ctx->state == EMM_STATE_DEREGISTERED) + { + //Attach requested from attach request + m_mme_gtpc->send_modify_bearer_request(ecm_ctx->imsi, &ecm_ctx->erabs_ctx[act_bearer.eps_bearer_id]); + //Send reply to eNB + m_s1ap_log->console("Packing EMM infromationi\n"); + *reply_flag = pack_emm_information(ecm_ctx, reply_msg); + m_s1ap_log->console("Sending EMM infromation, bytes %d\n",reply_msg->N_bytes); + m_s1ap_log->info("Sending EMM infromation\n"); + } + emm_ctx->state = EMM_STATE_REGISTERED; return true; } @@ -897,7 +906,7 @@ s1ap_nas_transport::handle_esm_information_response(srslte::byte_buffer_t *nas_m //FIXME The packging of GTP-C messages is not ready. //This means that GTP-U tunnels are created with function calls, as opposed to GTP-C. - m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi,true); + m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi); return true; } @@ -1756,7 +1765,7 @@ s1ap_nas_transport::pack_emm_information( ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte LIBLTE_MME_EMM_INFORMATION_MSG_STRUCT emm_info; emm_info.full_net_name_present = true; - emm_info.full_net_name.name = std::string("srsLTE"); + emm_info.full_net_name.name = std::string("Software Radio Systems LTE"); emm_info.full_net_name.add_ci = LIBLTE_MME_ADD_CI_DONT_ADD; emm_info.short_net_name_present = true; emm_info.short_net_name.name = std::string("srsLTE"); @@ -1771,7 +1780,7 @@ s1ap_nas_transport::pack_emm_information( ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte return false; uint8_t sec_hdr_type =2; - //ue_emm_ctx->security_ctxt.dl_nas_count++; + // ue_emm_ctx->security_ctxt.dl_nas_count++; LIBLTE_ERROR_ENUM err = liblte_mme_pack_emm_information_msg(&emm_info, sec_hdr_type, ue_emm_ctx->security_ctxt.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); if(err != LIBLTE_SUCCESS) { diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index b16b89c27..6444b8503 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -144,8 +144,8 @@ spgw::stop() std::map::iterator it = m_teid_to_tunnel_ctx.begin(); //Map control TEID to tunnel ctx. Usefull to get reply ctrl TEID, UE IP, etc. while(it!=m_teid_to_tunnel_ctx.end()) { - m_spgw_log->info("Deleting SP-GW Tunnel. IMSI: %lu\n", it->second->imsi); - m_spgw_log->console("Deleting SP-GW Tunnel. IMSI: %lu\n", it->second->imsi); + m_spgw_log->info("Deleting SP-GW GTP-C Tunnel. IMSI: %lu\n", it->second->imsi); + m_spgw_log->console("Deleting SP-GW GTP-C Tunnel. IMSI: %lu\n", it->second->imsi); delete it->second; m_teid_to_tunnel_ctx.erase(it++); } @@ -437,7 +437,7 @@ spgw::get_new_ue_ipv4() } void -spgw::handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu, bool pack_attach) +spgw::handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu) { srslte::gtpc_header *header = &cs_resp_pdu->header; srslte::gtpc_create_session_response *cs_resp = &cs_resp_pdu->choice.create_session_response; @@ -492,7 +492,7 @@ spgw::handle_create_session_request(struct srslte::gtpc_create_session_request * cs_resp->paa.ipv4_present = true; cs_resp->paa.ipv4 = ue_ip; m_spgw_log->info("Sending Create Session Response\n"); - m_mme_gtpc->handle_create_session_response(cs_resp_pdu, pack_attach ); + m_mme_gtpc->handle_create_session_response(cs_resp_pdu); return; } From ff8818590a4b1fdf7644a1e7953d4825c2c5397c Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 9 Mar 2018 21:30:33 +0000 Subject: [PATCH 076/143] Changing SPGW's handle_create_session_request to check weather GTP context already exists. --- srsepc/hdr/spgw/spgw.h | 6 ++ srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 14 ++-- srsepc/src/mme/s1ap_nas_transport.cc | 10 +-- srsepc/src/spgw/spgw.cc | 92 ++++++++++++++++++++++----- 4 files changed, 96 insertions(+), 26 deletions(-) diff --git a/srsepc/hdr/spgw/spgw.h b/srsepc/hdr/spgw/spgw.h index c68626f9c..e82d3f6ea 100644 --- a/srsepc/hdr/spgw/spgw.h +++ b/srsepc/hdr/spgw/spgw.h @@ -95,6 +95,10 @@ private: uint64_t get_new_user_teid(); in_addr_t get_new_ue_ipv4(); + spgw_tunnel_ctx_t* create_gtp_ctx(struct srslte::gtpc_create_session_request *cs_req); + bool delete_gtp_ctx(uint32_t ctrl_teid); + + bool m_running; srslte::byte_buffer_pool *m_pool; mme_gtpc *m_mme_gtpc; @@ -113,6 +117,8 @@ private: sockaddr_in m_s1u_addr; pthread_mutex_t m_mutex; + + std::map m_imsi_to_ctr_teid; //IMSI to control TEID map. Important to check if UE is previously connected std::map m_teid_to_tunnel_ctx; //Map control TEID to tunnel ctx. Usefull to get reply ctrl TEID, UE IP, etc. std::map m_ip_to_teid; //Map IP to User-plane TEID for downlink traffic diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index a1ed611ee..eacccb5c7 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -163,6 +163,8 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, if(emm_ctx->state == EMM_STATE_DEREGISTERED) { //Attach procedure initiated from an attach request + m_s1ap_log->console("Adding attach accept to Initial Context Setup Request\n"); + m_s1ap_log->info("Adding attach accept to Initial Context Setup Request\n"); m_s1ap_nas_transport->pack_attach_accept(emm_ctx, ecm_ctx, erab_ctx_req, &erab_ctx->pdn_addr_alloc, nas_buffer); } @@ -202,12 +204,17 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, bool s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT *in_ctxt_resp) { - static bool send_modify = false; uint32_t mme_ue_s1ap_id = in_ctxt_resp->MME_UE_S1AP_ID.MME_UE_S1AP_ID; ue_ecm_ctx_t *ue_ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); if (ue_ecm_ctx == NULL) { - m_s1ap_log->error("Could not find UE's context in active UE's map\n"); + m_s1ap_log->error("Could not find UE's ECM context in active UE's map\n"); + return false; + } + ue_emm_ctx_t *emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); + if (emm_ctx == NULL) + { + m_s1ap_log->error("Could not find UE's EMM context in active UE's map\n"); return false; } @@ -243,11 +250,10 @@ s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_I m_s1ap_log->console("E-RAB Context -- eNB TEID 0x%x; eNB GTP-U Address %s\n", erab_ctx->enb_fteid.teid, enb_addr_str); } - if(send_modify) + if(emm_ctx->state == EMM_STATE_DEREGISTERED) { m_mme_gtpc->send_modify_bearer_request(ue_ecm_ctx->imsi, &ue_ecm_ctx->erabs_ctx[5]); } - send_modify = true; return true; } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 75a53aa40..fb464c26f 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -363,7 +363,7 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, ue_emm_ctx.imsi += attach_req.eps_mobile_id.imsi[i]*std::pow(10,14-i); } ue_emm_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); - + ue_emm_ctx.state = EMM_STATE_DEREGISTERED; //Save UE network capabilities memcpy(&ue_emm_ctx.security_ctxt.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); ue_emm_ctx.security_ctxt.ms_network_cap_present = attach_req.ms_network_cap_present; @@ -671,9 +671,9 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, //Delete eNB context and connect. m_s1ap_log->console("Service Request -- User has ECM context already\n"); m_s1ap_log->info("Service Request -- User has ECM context already\n"); - //m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); - int default_bearer_id = 5; - m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[default_bearer_id]); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); + //int default_bearer_id = 5; + //m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[default_bearer_id]); } else { @@ -1780,7 +1780,7 @@ s1ap_nas_transport::pack_emm_information( ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte return false; uint8_t sec_hdr_type =2; - // ue_emm_ctx->security_ctxt.dl_nas_count++; + ue_emm_ctx->security_ctxt.dl_nas_count++; LIBLTE_ERROR_ENUM err = liblte_mme_pack_emm_information_msg(&emm_info, sec_hdr_type, ue_emm_ctx->security_ctxt.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); if(err != LIBLTE_SUCCESS) { diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index 6444b8503..0acb37041 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -417,6 +417,10 @@ spgw::handle_s1u_pdu(srslte::byte_buffer_t *msg) } return; } + +/* + * Helper Functions + */ uint64_t spgw::get_new_ctrl_teid() { @@ -436,61 +440,115 @@ spgw::get_new_ue_ipv4() return ntohl(m_h_next_ue_ip);//FIXME Tmp hack } -void -spgw::handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu) +spgw_tunnel_ctx_t* +spgw::create_gtp_ctx(struct srslte::gtpc_create_session_request *cs_req) { - srslte::gtpc_header *header = &cs_resp_pdu->header; - srslte::gtpc_create_session_response *cs_resp = &cs_resp_pdu->choice.create_session_response; - - - m_spgw_log->info("Received Create Session Request\n"); - //Setup uplink control TEID + //Setup uplink control TEID uint64_t spgw_uplink_ctrl_teid = get_new_ctrl_teid(); //Setup uplink user TEID uint64_t spgw_uplink_user_teid = get_new_user_teid(); //Allocate UE IP - //in_addr_t ue_ip = get_new_ue_ipv4(); - in_addr_t ue_ip = inet_addr("172.16.0.2"); + in_addr_t ue_ip = get_new_ue_ipv4(); + //in_addr_t ue_ip = inet_addr("172.16.0.2"); uint8_t default_bearer_id = 5; + m_spgw_log->console("SPGW: Allocated Ctrl TEID %d\n", spgw_uplink_ctrl_teid); + m_spgw_log->console("SPGW: Allocated User TEID %d\n", spgw_uplink_user_teid); + struct in_addr ue_ip_; + ue_ip_.s_addr=ue_ip; + m_spgw_log->console("SPGW: Allocate UE IP %s\n", inet_ntoa(ue_ip_)); + + //Save the UE IP to User TEID map spgw_tunnel_ctx_t *tunnel_ctx = new spgw_tunnel_ctx_t; + bzero(tunnel_ctx,sizeof(spgw_tunnel_ctx_t)); + tunnel_ctx->imsi = cs_req->imsi; tunnel_ctx->ebi = default_bearer_id; tunnel_ctx->up_user_fteid.teid = spgw_uplink_user_teid; tunnel_ctx->up_user_fteid.ipv4 = m_s1u_addr.sin_addr.s_addr; tunnel_ctx->dw_ctrl_fteid.teid = cs_req->sender_f_teid.teid; tunnel_ctx->dw_ctrl_fteid.ipv4 = cs_req->sender_f_teid.ipv4; - + tunnel_ctx->up_ctrl_fteid.teid = spgw_uplink_ctrl_teid; tunnel_ctx->ue_ipv4 = ue_ip; m_teid_to_tunnel_ctx.insert(std::pair(spgw_uplink_ctrl_teid,tunnel_ctx)); + m_imsi_to_ctr_teid.insert(std::pair(cs_req->imsi,spgw_uplink_ctrl_teid)); + return tunnel_ctx; +} + +bool +spgw::delete_gtp_ctx(uint32_t ctrl_teid) +{ + spgw_tunnel_ctx_t *tunnel_ctx; + if(!m_teid_to_tunnel_ctx.count(ctrl_teid)){ + m_spgw_log->error("Could not find GTP context to delete.\n"); + return false; + } + tunnel_ctx = m_teid_to_tunnel_ctx[ctrl_teid]; + + //Remove GTP-U connections, if any. + if(m_ip_to_teid.count(tunnel_ctx->ue_ipv4)) + { + pthread_mutex_lock(&m_mutex); + m_ip_to_teid.erase(tunnel_ctx->ue_ipv4); + pthread_mutex_unlock(&m_mutex); + } + //Remove Ctrl TEID from IMSI to control TEID map + m_imsi_to_ctr_teid.erase(tunnel_ctx->imsi); + + //Remove GTP context from control TEID mapping + m_teid_to_tunnel_ctx.erase(ctrl_teid); + delete tunnel_ctx; + return true; +} + +void +spgw::handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu) +{ + m_spgw_log->info("Received Create Session Request\n"); + spgw_tunnel_ctx_t *tunnel_ctx; + int default_bearer_id = 5; + //Check if IMSI has active GTP-C and/or GTP-U + bool gtpc_present = m_imsi_to_ctr_teid.count(cs_req->imsi); + if(gtpc_present) + { + m_spgw_log->console("SPGW: GTP-C context for IMSI %015ul already exists.\n", cs_req->imsi); + delete_gtp_ctx(m_imsi_to_ctr_teid[cs_req->imsi]); + m_spgw_log->console("SPGW: Deleted previous context.\n"); + } + + m_spgw_log->info("Creating new GTP-C context\n"); + tunnel_ctx = create_gtp_ctx(cs_req); //Create session response message + srslte::gtpc_header *header = &cs_resp_pdu->header; + srslte::gtpc_create_session_response *cs_resp = &cs_resp_pdu->choice.create_session_response; + //Setup GTP-C header header->piggyback = false; header->teid_present = true; - header->teid = cs_req->sender_f_teid.teid; //Send create session requesponse to the CS Request TEID + header->teid = tunnel_ctx->dw_ctrl_fteid.teid; //Send create session requesponse to the UE's MME Ctrl TEID header->type = srslte::GTPC_MSG_TYPE_CREATE_SESSION_RESPONSE; + //Initialize to zero bzero(cs_resp,sizeof(struct srslte::gtpc_create_session_response)); //Setup Cause cs_resp->cause.cause_value = srslte::GTPC_CAUSE_VALUE_REQUEST_ACCEPTED; //Setup sender F-TEID (ctrl) cs_resp->sender_f_teid.ipv4_present = true; - cs_resp->sender_f_teid.teid = spgw_uplink_ctrl_teid; - cs_resp->sender_f_teid.ipv4 = 0;//FIXME This is not relevant, as the GTP-C is not transmitted over sockets yet. + cs_resp->sender_f_teid = tunnel_ctx->up_ctrl_fteid; + //Bearer context created cs_resp->eps_bearer_context_created.ebi = default_bearer_id; cs_resp->eps_bearer_context_created.cause.cause_value = srslte::GTPC_CAUSE_VALUE_REQUEST_ACCEPTED; cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid_present=true; - cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.teid = spgw_uplink_user_teid; - cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.ipv4 = m_s1u_addr.sin_addr.s_addr; + cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid = tunnel_ctx->up_user_fteid; //Fill in the PAA cs_resp->paa_present = true; cs_resp->paa.pdn_type = srslte::GTPC_PDN_TYPE_IPV4; cs_resp->paa.ipv4_present = true; - cs_resp->paa.ipv4 = ue_ip; + cs_resp->paa.ipv4 = tunnel_ctx->ue_ipv4; m_spgw_log->info("Sending Create Session Response\n"); m_mme_gtpc->handle_create_session_response(cs_resp_pdu); return; From be09457ccb6d27f42e3359b9c0610a2155647359 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 12 Mar 2018 16:18:32 +0000 Subject: [PATCH 077/143] Starting to make sure that UL S1-U fteid and S11 SGW ctr fteid are kept, even when UE context release is called. --- srsepc/hdr/mme/s1ap_common.h | 19 +---- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 16 ++-- srsepc/src/mme/s1ap_nas_transport.cc | 112 ++++++++++++++++---------- 3 files changed, 83 insertions(+), 64 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index 7ffaf3434..5bb60e5a6 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -82,6 +82,7 @@ enum erab_state ERAB_ACTIVE }; + typedef struct{ uint8_t mme_code; uint16_t mme_group; @@ -139,9 +140,7 @@ typedef struct{ emm_state_t state; uint32_t mme_ue_s1ap_id; uint8_t attach_type; - //enum nas_init_msg init_msg; - //enum emm_connection_management conn_mngmnt_state; - //enum emm_common_proc common_proc_state; + srslte::gtpc_f_teid_ie sgw_ctrl_fteid; } ue_emm_ctx_t; typedef struct{ @@ -150,24 +149,14 @@ typedef struct{ uint32_t mme_ue_s1ap_id; struct sctp_sndrcvinfo enb_sri; ecm_state_t state; - srslte::gtpc_f_teid_ie sgw_ctrl_fteid; erab_ctx_t erabs_ctx[MAX_ERABS_PER_UE]; bool eit; } ue_ecm_ctx_t; typedef struct{ - uint64_t imsi; - uint32_t enb_ue_s1ap_id; - uint32_t mme_ue_s1ap_id; - uint16_t enb_id; - struct sctp_sndrcvinfo enb_sri; - emm_state_t emm_state; - eps_security_ctx_t security_ctxt; - erab_ctx_t erabs_ctx[MAX_ERABS_PER_UE]; - bool eit; - uint8_t procedure_transaction_id; - uint8_t attach_type; + ue_emm_ctx_t emm_ctx; + ue_ecm_ctx_t ecm_ctx; } ue_ctx_t; }//namespace #endif diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index eacccb5c7..34e0c8db3 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -216,8 +216,8 @@ s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_I { m_s1ap_log->error("Could not find UE's EMM context in active UE's map\n"); return false; - } - + } + m_s1ap_log->console("Received Initial Context Setup Response\n"); //Setup E-RABs for(uint32_t i=0; iE_RABSetupListCtxtSURes.len;i++) { @@ -250,8 +250,10 @@ s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_I m_s1ap_log->console("E-RAB Context -- eNB TEID 0x%x; eNB GTP-U Address %s\n", erab_ctx->enb_fteid.teid, enb_addr_str); } - if(emm_ctx->state == EMM_STATE_DEREGISTERED) + if(emm_ctx->state == EMM_STATE_REGISTERED) { + m_s1ap_log->console("Initial Context Setup Response triggered from Service Request.\n"); + m_s1ap_log->console("Sending Modify Bearer Request.\n"); m_mme_gtpc->send_modify_bearer_request(ue_ecm_ctx->imsi, &ue_ecm_ctx->erabs_ctx[5]); } return true; @@ -279,6 +281,8 @@ s1ap_ctx_mngmt_proc::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECON if (ecm_ctx->state == ECM_STATE_CONNECTED) { //There are active E-RABs, send release access mearers request + m_s1ap_log->console("There are active E-RABs, send release access mearers request"); + m_s1ap_log->info("There are active E-RABs, send release access mearers request"); m_mme_gtpc->send_release_access_bearers_request(ecm_ctx->imsi); } else @@ -293,8 +297,10 @@ s1ap_ctx_mngmt_proc::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECON ecm_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; } //Delete UE context - m_s1ap->delete_ue_ecm_ctx(ecm_ctx->mme_ue_s1ap_id); - m_s1ap_log->info("Deleted UE ECM Context.\n"); + ecm_ctx->state = ECM_STATE_DISCONNECTED; + ecm_ctx->mme_ue_s1ap_id = 0; + m_s1ap_log->info("UE ECM Disconnected.\n"); + m_s1ap_log->console("Deleted UE ECM Context.\n"); return true; } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index fb464c26f..2227cddda 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -492,6 +492,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, //Set tmp UE EMM context tmp_ue_emm_ctx.imsi = 0; + tmp_ue_emm_ctx.state = EMM_STATE_DEREGISTERED; //Save UE network capabilities memcpy(&tmp_ue_emm_ctx.security_ctxt.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); @@ -570,6 +571,8 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, //Create new MME UE S1AP Identity ue_emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + //Set EMM as de-registered + ue_emm_ctx->state = EMM_STATE_DEREGISTERED; //Save Attach type ue_emm_ctx->attach_type = attach_req.eps_attach_type; //Create UE ECM context @@ -602,7 +605,9 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, //NAS integrity failed. Re-start authentication process. m_s1ap_log->console("GUTI Attach request NAS integrity failed.\n"); m_s1ap_log->console("RE-starting authentication procedure.\n"); - //FIXME + //pack_identity_request(); + //(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id) + return true; } } else @@ -660,61 +665,80 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, m_s1ap_log->console("Service Request -- Short MAC valid\n"); m_s1ap_log->info("Service Request -- Short MAC valid\n"); ue_ecm_ctx_t *ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(emm_ctx->mme_ue_s1ap_id); - if(ecm_ctx !=NULL) + if(ecm_ctx == NULL) { - //Service request to Connected UE. - //Set eNB UE S1ap identity - ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; - m_s1ap_log->console("Service Request -- eNB UE S1AP Id %d \n", enb_ue_s1ap_id); - m_s1ap_log->info("Service Request -- eNB UE S1AP Id %d\n ", enb_ue_s1ap_id); - - //Delete eNB context and connect. - m_s1ap_log->console("Service Request -- User has ECM context already\n"); - m_s1ap_log->info("Service Request -- User has ECM context already\n"); - m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); - //int default_bearer_id = 5; - //m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[default_bearer_id]); + m_s1ap_log->console("UE ECM context is not initialized.\n"); + m_s1ap_log->error("UE ECM context is not initialized.\n"); + pack_service_reject(reply_buffer, LIBLTE_MME_EMM_CAUSE_IMPLICITLY_DETACHED, enb_ue_s1ap_id); + *reply_flag = true; + return true; } else { - ue_ecm_ctx_t ue_ecm_ctx; - ue_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; - - //UE not connect. Connect normally. - m_s1ap_log->console("Service Request -- User without ECM context\n"); - m_s1ap_log->info("Service Request -- User without ECM context\n"); - //Create ECM context - ue_ecm_ctx.imsi = emm_ctx->imsi; - ue_ecm_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); - emm_ctx->mme_ue_s1ap_id = ue_ecm_ctx.mme_ue_s1ap_id; - //Set eNB information - ue_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; - memcpy(&ue_ecm_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); - - //Save whether secure ESM information transfer is necessary - ue_ecm_ctx.eit = false; - - //Initialize E-RABs - for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) + if(ecm_ctx->state == ECM_STATE_CONNECTED) + { + m_s1ap_log->error("Service Request -- User is ECM CONNECTED\n"); + + //Service request to Connected UE. + //Set eNB UE S1ap identity + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + m_s1ap_log->console("Service Request -- eNB UE S1AP Id %d \n", enb_ue_s1ap_id); + m_s1ap_log->info("Service Request -- eNB UE S1AP Id %d\n ", enb_ue_s1ap_id); + + //Delete eNB context and connect. + m_s1ap_log->console("Service Request -- User has ECM context already\n"); + m_s1ap_log->info("Service Request -- User has ECM context already\n"); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); + //int default_bearer_id = 5; + //m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[default_bearer_id]); + //FIXME Send Modify context request OR send ctx release command and wait for the reply. + + } + else if(ecm_ctx->state == ECM_STATE_DISCONNECTED) + { + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + + //UE not connect. Connect normally. + m_s1ap_log->console("Service Request -- User is ECM DISCONNECTED\n"); + m_s1ap_log->info("Service Request -- User is ECM DISCONNECTED\n"); + //Create ECM context + ecm_ctx->imsi = emm_ctx->imsi; + ecm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + emm_ctx->mme_ue_s1ap_id = ecm_ctx->mme_ue_s1ap_id; + //Set eNB information + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + + //Save whether secure ESM information transfer is necessary + ecm_ctx->eit = false; + + //Initialize E-RABs + for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) + { + ue_ecm_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED; + ue_ecm_ctx.erabs_ctx[i].erab_id = i; + } + ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(emm_ctx->mme_ue_s1ap_id); + + //Re-generate K_eNB + liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); + m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); + m_s1ap_log->console("UE Ctr TEID %d\n", emm_ctx->sgw_ctrl_fteid.teid); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx,&ecm_ctx->erabs_ctx[5]); + + } + else { - ue_ecm_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED; - ue_ecm_ctx.erabs_ctx[i].erab_id = i; + m_s1ap_log->console("ECM context is un-initialized.\n"); + m_s1ap_log->error("ECM context is un-initialized.\n"); } - memcpy(&ue_ecm_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); - m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); - - //Re-generate K_eNB - liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); - m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); - //FIXME Send Modify context request OR send ctx release command and wait for the reply. - m_mme_gtpc->send_create_session_request(ue_ecm_ctx.imsi); - m_s1ap_log->console("UE ESM Ctr TEID %d\n", ue_ecm_ctx.sgw_ctrl_fteid.teid); } } else { m_s1ap_log->console("Service Request -- Short MAC invalid. Re-starting authentication procedure \n"); m_s1ap_log->console("Service Request -- Short MAC invalid. Re-starting authentication procedure \n"); + m_s1ap_log->console("Authentication procedure is not restarted yet!\n"); } return true; } From be84ee854a1476c73592b18ffc51ab22e7924092 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 14 Mar 2018 11:14:44 +0000 Subject: [PATCH 078/143] Changing the way that ECM context is stored to keep uplink teids active when the context is release. --- srsepc/hdr/mme/s1ap.h | 32 +- srsepc/hdr/mme/s1ap_common.h | 6 +- srsepc/hdr/mme/s1ap_nas_transport.h | 16 +- srsepc/src/mme/mme_gtpc.cc | 13 +- srsepc/src/mme/s1ap.cc | 339 +++++++++++++++----- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 50 +-- srsepc/src/mme/s1ap_nas_transport.cc | 426 ++++++++++++-------------- 7 files changed, 516 insertions(+), 366 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 311a65784..52d435fbd 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -66,7 +66,7 @@ public: int get_s1_mme(); void delete_enb_ctx(int32_t assoc_id); - void delete_ues_in_enb(uint16_t enb_id); + void release_ues_ecm_ctx_in_enb(uint16_t enb_id); bool handle_s1ap_rx_pdu(srslte::byte_buffer_t *pdu, struct sctp_sndrcvinfo *enb_sri); bool handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri); @@ -81,16 +81,20 @@ public: enb_ctx_t* find_enb_ctx(uint16_t enb_id); void add_new_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo* enb_sri); - ue_ctx_t* find_ue_ctx(uint32_t mme_ue_s1ap_id); void add_new_ue_ctx(const ue_ctx_t &ue_ctx); + ue_ctx_t* find_ue_ctx_from_imsi(uint64_t imsi); + ue_ctx_t* find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id); - void add_new_ue_emm_ctx(const ue_emm_ctx_t &ue_emm_ctx); - void add_new_ue_ecm_ctx(const ue_ecm_ctx_t &ue_ecm_ctx); - ue_emm_ctx_t* find_ue_emm_ctx_from_imsi(uint64_t imsi); - ue_ecm_ctx_t* find_ue_ecm_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id); - bool delete_ue_emm_ctx(uint64_t imsi); - bool delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id); - void delete_ues_ecm_ctx_in_enb(uint16_t enb_id); + //ue_ctx_t* find_ue_ctx(uint32_t mme_ue_s1ap_id); + //void add_new_ue_ctx(const ue_ctx_t &ue_ctx); + + //void add_new_ue_emm_ctx(const ue_emm_ctx_t &ue_emm_ctx); + //void add_new_ue_ecm_ctx(const ue_ecm_ctx_t &ue_ecm_ctx); + //ue_emm_ctx_t* find_ue_emm_ctx_from_imsi(uint64_t imsi); + //ue_ecm_ctx_t* find_ue_ecm_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id); + //bool delete_ue_emm_ctx(uint64_t imsi); + //bool delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id); + //void delete_ues_ecm_ctx_in_enb(uint16_t enb_id); void store_tmp_ue_emm_ctx(const ue_emm_ctx_t &ue_ecm_ctx); bool get_tmp_ue_emm_ctx(uint32_t mme_ue_s1ap_id, ue_emm_ctx_t* ue_emm_ptr); @@ -122,9 +126,13 @@ private: std::map m_sctp_to_enb_id; std::map > m_enb_id_to_ue_ids; - std::map m_imsi_to_ue_emm_ctx; - std::map m_mme_ue_s1ap_id_to_ue_ecm_ctx; - std::map m_mme_ue_s1ap_id_to_tmp_ue_emm_ctx; + + std::map m_imsi_to_ue_ctx; + std::map m_mme_ue_s1ap_id_to_ue_ctx; + + //std::map m_imsi_to_ue_emm_ctx; + //std::map m_mme_ue_s1ap_id_to_ue_ecm_ctx; + //std::map m_mme_ue_s1ap_id_to_tmp_ue_emm_ctx; uint32_t m_next_mme_ue_s1ap_id; uint32_t m_next_m_tmsi; diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index 5bb60e5a6..adb9f68e0 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -122,7 +122,7 @@ typedef struct{ LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT ue_network_cap; bool ms_network_cap_present; LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT ms_network_cap; -} eps_security_ctx_t; +} eps_sec_ctx_t; typedef struct{ enum erab_state state; @@ -135,7 +135,7 @@ typedef struct{ typedef struct{ uint64_t imsi; LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT guti; - eps_security_ctx_t security_ctxt; + eps_sec_ctx_t security_ctxt; uint8_t procedure_transaction_id; emm_state_t state; uint32_t mme_ue_s1ap_id; @@ -156,7 +156,9 @@ typedef struct{ typedef struct{ ue_emm_ctx_t emm_ctx; + eps_sec_ctx_t sec_ctx; ue_ecm_ctx_t ecm_ctx; + erab_ctx_t erabs_ctx[MAX_ERABS_PER_UE]; } ue_ctx_t; }//namespace #endif diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index b107eb010..7ce83f363 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -72,14 +72,14 @@ public: srslte::byte_buffer_t *reply_buffer, bool* reply_flag, struct sctp_sndrcvinfo *enb_sri); - bool handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag); - bool handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); - bool handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); - bool handle_esm_information_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); - bool handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); - bool handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); + bool handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag); + bool handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); + bool handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); + bool handle_esm_information_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); + bool handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); + bool handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); - bool handle_authentication_failure(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); + bool handle_authentication_failure(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu); bool short_integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu); @@ -94,7 +94,7 @@ public: bool pack_attach_accept(ue_emm_ctx_t *ue_emm_ctx, ue_ecm_ctx_t *ue_ecm_ctx, LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctxt, struct srslte::gtpc_pdn_address_allocation_ie *paa, srslte::byte_buffer_t *nas_buffer); bool pack_identity_request(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id); - bool pack_emm_information(ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg); + bool pack_emm_information(ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg); bool pack_service_reject(srslte::byte_buffer_t *reply_msg, uint8_t emm_cause, uint32_t enb_ue_s1ap_id); void log_unhandled_attach_request_ies(const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT *attach_req); diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 595166494..53277e89c 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -214,16 +214,13 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu) } //Save create session response info to E-RAB context - ue_emm_ctx_t *emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(imsi); - if(emm_ctx == NULL){ - m_mme_gtpc_log->error("Could not find UE EMM context\n"); - return; - } - ue_ecm_ctx_t *ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(emm_ctx->mme_ue_s1ap_id); - if(ecm_ctx == NULL){ - m_mme_gtpc_log->error("Could not find UE ECM context\n"); + ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_imsi(imsi); + if(ue_ctx == NULL){ + m_mme_gtpc_log->error("Could not find UE context\n"); return; } + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; //Save SGW ctrl F-TEID in GTP-C context std::map::iterator it_g = m_imsi_to_gtpc_ctx.find(imsi); diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 845675057..e59740299 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -113,18 +113,17 @@ s1ap::stop() { m_s1ap_log->info("Deleting eNB context. eNB Id: 0x%x\n", enb_it->second->enb_id); m_s1ap_log->console("Deleting eNB context. eNB Id: 0x%x\n", enb_it->second->enb_id); - delete_ues_ecm_ctx_in_enb(enb_it->second->enb_id); delete enb_it->second; m_active_enbs.erase(enb_it++); } - std::map::iterator ue_it = m_imsi_to_ue_emm_ctx.begin(); - while(ue_it!=m_imsi_to_ue_emm_ctx.end()) + std::map::iterator ue_it = m_imsi_to_ue_ctx.begin(); + while(ue_it!=m_imsi_to_ue_ctx.end()) { m_s1ap_log->info("Deleting UE EMM context. IMSI: %015lu\n", ue_it->first); m_s1ap_log->console("Deleting UE EMM context. IMSI: %015lu\n", ue_it->first); delete ue_it->second; - m_imsi_to_ue_emm_ctx.erase(ue_it++); + m_imsi_to_ue_ctx.erase(ue_it++); } //Cleanup message handlers s1ap_mngmt_proc::cleanup(); @@ -336,7 +335,7 @@ s1ap::delete_enb_ctx(int32_t assoc_id) m_s1ap_log->console("Deleting eNB context. eNB Id: 0x%x\n", enb_id); //Delete connected UEs ctx - delete_ues_ecm_ctx_in_enb(enb_id); + release_ues_ecm_ctx_in_enb(enb_id); //Delete eNB delete it_ctx->second; @@ -348,20 +347,89 @@ s1ap::delete_enb_ctx(int32_t assoc_id) //UE Context Management void -s1ap::add_new_ue_emm_ctx(const ue_emm_ctx_t &ue_emm_ctx) +s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) { - std::map::iterator emm_ctx_it = m_imsi_to_ue_emm_ctx.find(ue_emm_ctx.imsi); - if(emm_ctx_it != m_imsi_to_ue_emm_ctx.end()) + std::map::iterator ctx_it = m_imsi_to_ue_ctx.find(ue_ctx.emm_ctx.imsi); + if(ctx_it != m_imsi_to_ue_ctx.end()) { - m_s1ap_log->warning("EMM Context already exists. Replacing EMM Context\n"); - delete emm_ctx_it->second; - m_imsi_to_ue_emm_ctx.erase(emm_ctx_it); + m_s1ap_log->warning("UE Context already exists. Replacing UE Context\n"); + delete ctx_it->second; + m_imsi_to_ue_ctx.erase(ctx_it); + } + std::map::iterator imsi_it = m_mme_ue_s1ap_id_to_imsi.find(ue_ctx.ecm_ctx.mme_ue_s1ap_id); + if(imsi_it != m_mme_ue_s1ap_id_to_imsi.end()) + { + m_s1ap_log->warning("MME UE S1AP Id already exists, replacing it.\n"); + m_mme_ue_s1ap_id_to_imsi.erase(imsi_it); } - ue_emm_ctx_t *ue_ptr = new ue_emm_ctx_t; - memcpy(ue_ptr,&ue_emm_ctx,sizeof(ue_emm_ctx)); - //This map will store UEs EMM context - m_imsi_to_ue_emm_ctx.insert(std::pair(ue_ptr->imsi,ue_ptr)); + ue_ctx_t *new_ctx = new ue_ctx_t; + memcpy(new_ctx, &ue_ctx,sizeof(ue_ctx)); + + //This map will store UEs context + m_imsi_to_ue_ctx.insert(std::pair(new_ctx->emm_ctx.imsi,new_ctx)); + m_mme_ue_s1ap_id_to_imsi.insert(std::pair(ue_ctx.ecm_ctx.mme_ue_s1ap_id,ue_ctx.emm_ctx.imsi)); + + //Store which enb currently holds the UE + std::map::iterator it_enb = m_sctp_to_enb_id.find(new_ctx->ecm_ctx.enb_sri.sinfo_assoc_id); + uint16_t enb_id = it_enb->second; + std::map >::iterator it_ue_id = m_enb_id_to_ue_ids.find(enb_id); + if(it_ue_id==m_enb_id_to_ue_ids.end()) + { + m_s1ap_log->error("Could not find eNB's UEs\n"); + return; + } + it_ue_id->second.insert(new_ctx->ecm_ctx.mme_ue_s1ap_id); + return; +} + +bool +s1ap::add_ue_ctx_to_imsi_map(const ue_ctx_t *ue_ctx) +{ + std::map::iterator ctx_it = m_imsi_to_ue_ctx.find(ue_ctx->emm_ctx.imsi); + if(ctx_it != m_imsi_to_ue_ctx.end()) + { + m_s1ap_log->error("UE Context already exists. IMSI %015lu",ue_ctx->emm_ctx.imsi); + return false; + } + if(ue_ctx->ecm_ctx.mme_ue_s1ap_id != 0) + { + std::map::iterator ctx_it2 = m_mme_ue_s1ap_id_to_ue_ctx.find(ue_ctx.ecm_ctx.mme_ue_s1ap_id); + if(ctx_it2 != m_mme_ue_s1ap_id_to_imsi.end() && ctx_it2->second != ue_ctx) + { + m_s1ap_log->error("Context identified with IMSI does not match context identified by MME UE S1AP Id.\n"); + return false; + } + } + return true; +} + +bool +s1ap::add_ue_ctx_to_mme_ue_s1ap_id_map(const ue_ctx_t *ue_ctx) +{ + if(ue_ctx->ecm_ctx.mme_ue_s1ap_id == 0) + { + m_s1ap_log->error("Could not add UE context to MME UE S1AP map. MME UE S1AP ID 0 is not valid.") + return false; + } + std::map::iterator ctx_it = m_mme_ue_s1ap_id_to_ue_ctx.find(ue_ctx->ecm_ctx.mme_ue_s1ap_id); + if(ctx_it != m_mme_ue_s1ap_id_to_ue_ctx.end()) + { + m_s1ap_log->error("UE Context already exists. MME UE S1AP Id %015lu",ue_ctx->emm_ctx.imsi); + return false; + } + if(ue_ctx->ecm_ctx.imsi != 0) + { + std::map::iterator ctx_it2 = m_mme_ue_s1ap_id_to_ue_ctx.find(ue_ctx.ecm_ctx.mme_ue_s1ap_id); + if(ctx_it2 != m_mme_ue_s1ap_id_to_imsi.end() && ctx_it2->second != ue_ctx) + { + m_s1ap_log->error("Context identified with MME UE S1AP Id does not match context identified by IMSI.\n"); + return false; + } + } + + + return true; } void @@ -389,32 +457,11 @@ s1ap::get_tmp_ue_emm_ctx(uint32_t mme_ue_s1ap_id, ue_emm_ctx_t* ue_emm_ptr) return true; } -void -s1ap::add_new_ue_ecm_ctx(const ue_ecm_ctx_t &ue_ecm_ctx) -{ - ue_ecm_ctx_t *ue_ptr = new ue_ecm_ctx_t; - memcpy(ue_ptr,&ue_ecm_ctx,sizeof(ue_ecm_ctx)); - - //This map will store UE's ECM context. - m_mme_ue_s1ap_id_to_ue_ecm_ctx.insert(std::pair(ue_ptr->mme_ue_s1ap_id,ue_ptr)); - //Store which enb currently holds the UE - std::map::iterator it_enb = m_sctp_to_enb_id.find(ue_ptr->enb_sri.sinfo_assoc_id); - uint16_t enb_id = it_enb->second; - std::map >::iterator it_ue_id = m_enb_id_to_ue_ids.find(enb_id); - if(it_ue_id==m_enb_id_to_ue_ids.end()) - { - m_s1ap_log->error("Could not find eNB's UEs\n"); - return; - } - it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); -} - - -ue_emm_ctx_t* -s1ap::find_ue_emm_ctx_from_imsi(uint64_t imsi) +ue_ctx_t* +s1ap::find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) { - std::map::iterator it = m_imsi_to_ue_emm_ctx.find(imsi); - if(it == m_imsi_to_ue_emm_ctx.end()) + std::map::iterator it = m_mme_ue_s1ap_id_to_ue_ctx.find(mme_ue_s1ap_id); + if(it == m_mme_ue_s1ap_id_to_imsi.end()) { return NULL; } @@ -424,11 +471,11 @@ s1ap::find_ue_emm_ctx_from_imsi(uint64_t imsi) } } -ue_ecm_ctx_t* -s1ap::find_ue_ecm_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) +ue_ctx_t* +s1ap::find_ue_ctx_from_imsi(uint64_t imsi) { - std::map::iterator it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_ue_s1ap_id); - if(it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) + std::map::iterator it = m_imsi_to_ue_ctx.find(imsi); + if(it == m_imsi_to_ue_ctx.end()) { return NULL; } @@ -437,39 +484,39 @@ s1ap::find_ue_ecm_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) return it->second; } } -bool -s1ap::delete_ue_emm_ctx(uint64_t imsi) + +void +s1ap::release_ues_ecm_ctx_in_enb(uint16_t enb_id) { - std::map::iterator ue_emm_ctx_it = m_imsi_to_ue_emm_ctx.find(imsi); - if(ue_emm_ctx_it == m_imsi_to_ue_emm_ctx.end()) + //delete UEs ctx + std::map >::iterator ues_in_enb = m_enb_id_to_ue_ids.find(enb_id); + std::set::iterator ue_id = ues_in_enb->second.begin(); + while(ue_id != ues_in_enb->second.end() ) { - m_s1ap_log->info("Cannot delete UE EMM context, UE not found. IMSI: %d\n", imsi); - return false; + std::map::iterator ue_ctx = m_mme_ue_s1ap_id_to_ue_ctx.find(*ue_id); + m_s1ap_log->info("Deleting UE context. UE-MME S1AP Id: %d\n", ue_ctx->second->mme_ue_s1ap_id); + m_s1ap_log->console("Deleting UE context. UE-MME S1AP Id: %d\n", ue_ctx->second->mme_ue_s1ap_id); + + ue_set->second.erase(mme_ue_s1ap_id); } - - //Delete UE context - m_imsi_to_ue_emm_ctx.erase(ue_emm_ctx_it); - delete ue_emm_ctx_it->second; - m_s1ap_log->info("Deleted UE EMM Context.\n"); - return true; } bool -s1ap::delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id) +s1ap::release_ue_ecm_ctx(uint32_t mme_ue_s1ap_id) { - std::map::iterator ue_ecm_ctx_it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_ue_s1ap_id); - if(ue_ecm_ctx_it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) + ue_ctx_t *ue_ctx = find_ue_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id) + if(ue_ctx == NULL) { - m_s1ap_log->info("Cannot delete UE ECM context, UE not found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + m_s1ap_log->error("Cannot release UE ECM context, UE not found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); return false; } - ue_ecm_ctx_t* ue_ecm_ctx = ue_ecm_ctx_it->second; + ue_ecm_ctx_t* ecm_ctx = &ue_ctx->ecm_ctx; //Delete UE within eNB UE set - std::map::iterator it = m_sctp_to_enb_id.find(ue_ecm_ctx->enb_sri.sinfo_assoc_id); + std::map::iterator it = m_sctp_to_enb_id.find(ecm_ctx->enb_sri.sinfo_assoc_id); if(it == m_sctp_to_enb_id.end() ) { - m_s1ap_log->error("Could not find eNB for this request.\n"); + m_s1ap_log->error("Could not find eNB for UE release request.\n"); return false; } uint16_t enb_id = it->second; @@ -481,31 +528,42 @@ s1ap::delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id) } ue_set->second.erase(mme_ue_s1ap_id); - //Delete UE context - m_mme_ue_s1ap_id_to_ue_ecm_ctx.erase(ue_ecm_ctx_it); - delete ue_ecm_ctx; - m_s1ap_log->info("Deleted UE ECM Context.\n"); + //Release UE ECM context + m_mme_ue_s1ap_id_to_imsi.erase(mme_ue_s1ap_id); + ecm_ctx->state = ECM_STATE_IDLE; + ecm_ctx->mme_ue_s1ap_id = 0; + ecm_ctx->enb_ue_s1ap_id = 0; + m_s1ap_log->info("Released UE ECM Context.\n"); return true; } -void -s1ap::delete_ues_ecm_ctx_in_enb(uint16_t enb_id) +bool +s1ap::delete_ue_ctx(uint64_t imsi) { - //delete UEs ctx - std::map >::iterator ues_in_enb = m_enb_id_to_ue_ids.find(enb_id); - std::set::iterator ue_id = ues_in_enb->second.begin(); - while(ue_id != ues_in_enb->second.end() ) + ue_ctx_t *ue_ctx = find_ue_ctx_from_imsi(imsi); + if(ue_ctx == NULL) { - std::map::iterator ue_ctx = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(*ue_id); - m_s1ap_log->info("Deleting UE context. UE-MME S1AP Id: %d\n", ue_ctx->second->mme_ue_s1ap_id); - m_s1ap_log->console("Deleting UE context. UE-MME S1AP Id: %d\n", ue_ctx->second->mme_ue_s1ap_id); - m_mme_ue_s1ap_id_to_ue_ecm_ctx.erase(ue_ctx); //remove from general MME map - delete ue_ctx->second; //delete UE context - ues_in_enb->second.erase(ue_id++); //erase from the eNB's UE set + m_s1ap_log->info("Cannot delete UE context, UE not found. IMSI: %d\n", imsi); + return false; + } + + //Make sure to release ECM ctx + if(ue_ctx->ecm_ctx.state == ECM_STATE_CONNECTED) + { + release_ue_ecm_ctx(ue_ctx->ecm_state.mme_ue_s1ap_id); } + + //Delete UE context + m_imsi_to_ue_ctx.erase(imsi); + delete ue_ctx; + m_s1ap_log->info("Deleted UE Context.\n"); + return true; } + + + //UE Bearer Managment void s1ap::activate_eps_bearer(uint64_t imsi, uint8_t ebi) @@ -580,3 +638,126 @@ s1ap::print_enb_ctx_info(const std::string &prefix, const enb_ctx_t &enb_ctx) } } //namespace srsepc + + /* +void +s1ap::add_new_ue_emm_ctx(const ue_emm_ctx_t &ue_emm_ctx) +{ + std::map::iterator emm_ctx_it = m_imsi_to_ue_emm_ctx.find(ue_emm_ctx.imsi); + if(emm_ctx_it != m_imsi_to_ue_emm_ctx.end()) + { + m_s1ap_log->warning("EMM Context already exists. Replacing EMM Context\n"); + delete emm_ctx_it->second; + m_imsi_to_ue_emm_ctx.erase(emm_ctx_it); + } + + ue_emm_ctx_t *ue_ptr = new ue_emm_ctx_t; + memcpy(ue_ptr,&ue_emm_ctx,sizeof(ue_emm_ctx)); + //This map will store UEs EMM context + m_imsi_to_ue_emm_ctx.insert(std::pair(ue_ptr->imsi,ue_ptr)); +} + */ + +/* + void + s1ap::add_new_ue_ecm_ctx(const ue_ecm_ctx_t &ue_ecm_ctx) + { + ue_ecm_ctx_t *ue_ptr = new ue_ecm_ctx_t; + memcpy(ue_ptr,&ue_ecm_ctx,sizeof(ue_ecm_ctx)); + + //This map will store UE's ECM context. + m_mme_ue_s1ap_id_to_ue_ecm_ctx.insert(std::pair(ue_ptr->mme_ue_s1ap_id,ue_ptr)); + //Store which enb currently holds the UE + std::map::iterator it_enb = m_sctp_to_enb_id.find(ue_ptr->enb_sri.sinfo_assoc_id); + uint16_t enb_id = it_enb->second; + std::map >::iterator it_ue_id = m_enb_id_to_ue_ids.find(enb_id); + if(it_ue_id==m_enb_id_to_ue_ids.end()) + { + m_s1ap_log->error("Could not find eNB's UEs\n"); + return; + } + it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); + } + */ + /* +ue_emm_ctx_t* +s1ap::find_ue_emm_ctx_from_imsi(uint64_t imsi) +{ + std::map::iterator it = m_imsi_to_ue_emm_ctx.find(imsi); + if(it == m_imsi_to_ue_emm_ctx.end()) + { + return NULL; + } + else + { + return it->second; + } +} + +ue_ecm_ctx_t* +s1ap::find_ue_ecm_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) +{ + std::map::iterator it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_ue_s1ap_id); + if(it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) + { + return NULL; + } + else + { + return it->second; + } +}*/ + /* +bool +s1ap::delete_ue_emm_ctx(uint64_t imsi) +{ + std::map::iterator ue_emm_ctx_it = m_imsi_to_ue_emm_ctx.find(imsi); + if(ue_emm_ctx_it == m_imsi_to_ue_emm_ctx.end()) + { + m_s1ap_log->info("Cannot delete UE EMM context, UE not found. IMSI: %d\n", imsi); + return false; + } + + //Delete UE context + m_imsi_to_ue_emm_ctx.erase(ue_emm_ctx_it); + delete ue_emm_ctx_it->second; + m_s1ap_log->info("Deleted UE EMM Context.\n"); + return true; +} + */ + /* +bool +s1ap::delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id) +{ + std::map::iterator ue_ecm_ctx_it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_ue_s1ap_id); + if(ue_ecm_ctx_it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) + { + m_s1ap_log->info("Cannot delete UE ECM context, UE not found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + return false; + } + ue_ecm_ctx_t* ue_ecm_ctx = ue_ecm_ctx_it->second; + + //Delete UE within eNB UE set + std::map::iterator it = m_sctp_to_enb_id.find(ue_ecm_ctx->enb_sri.sinfo_assoc_id); + if(it == m_sctp_to_enb_id.end() ) + { + m_s1ap_log->error("Could not find eNB for this request.\n"); + return false; + } + uint16_t enb_id = it->second; + std::map >::iterator ue_set = m_enb_id_to_ue_ids.find(enb_id); + if(ue_set == m_enb_id_to_ue_ids.end()) + { + m_s1ap_log->error("Could not find the eNB's UEs.\n"); + return false; + } + ue_set->second.erase(mme_ue_s1ap_id); + + //Delete UE context + m_mme_ue_s1ap_id_to_ue_ecm_ctx.erase(ue_ecm_ctx_it); + delete ue_ecm_ctx; + m_s1ap_log->info("Deleted UE ECM Context.\n"); + + return true; +} + */ diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 34e0c8db3..3485b6e2f 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -205,27 +205,24 @@ bool s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT *in_ctxt_resp) { uint32_t mme_ue_s1ap_id = in_ctxt_resp->MME_UE_S1AP_ID.MME_UE_S1AP_ID; - ue_ecm_ctx_t *ue_ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); - if (ue_ecm_ctx == NULL) + ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); + if (ue_ctx == NULL) { - m_s1ap_log->error("Could not find UE's ECM context in active UE's map\n"); + m_s1ap_log->error("Could not find UE's context in active UE's map\n"); return false; } - ue_emm_ctx_t *emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); - if (emm_ctx == NULL) - { - m_s1ap_log->error("Could not find UE's EMM context in active UE's map\n"); - return false; - } + ue_emm_ctx_t * emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t * ecm_ctx = &ue_ctx->ecm_ctx; + m_s1ap_log->console("Received Initial Context Setup Response\n"); //Setup E-RABs for(uint32_t i=0; iE_RABSetupListCtxtSURes.len;i++) { uint8_t erab_id = in_ctxt_resp->E_RABSetupListCtxtSURes.buffer[i].e_RAB_ID.E_RAB_ID; - erab_ctx_t *erab_ctx = &ue_ecm_ctx->erabs_ctx[erab_id]; + erab_ctx_t *erab_ctx = &ecm_ctx->erabs_ctx[erab_id]; if (erab_ctx->state != ERAB_CTX_REQUESTED) { - m_s1ap_log->error("E-RAB requested was not active %d\n",erab_id); + m_s1ap_log->error("E-RAB requested was not previously requested %d\n",erab_id); return false; } //Mark E-RAB with context setup @@ -254,7 +251,7 @@ s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_I { m_s1ap_log->console("Initial Context Setup Response triggered from Service Request.\n"); m_s1ap_log->console("Sending Modify Bearer Request.\n"); - m_mme_gtpc->send_modify_bearer_request(ue_ecm_ctx->imsi, &ue_ecm_ctx->erabs_ctx[5]); + m_mme_gtpc->send_modify_bearer_request(emm_ctx->imsi, &ecm_ctx->erabs_ctx[5]); } return true; } @@ -269,13 +266,14 @@ s1ap_ctx_mngmt_proc::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECON m_s1ap_log->info("Received UE Context Release Request. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); m_s1ap_log->console("Received UE Context Release Request. MME-UE S1AP Id %d\n", mme_ue_s1ap_id); - ue_ecm_ctx_t *ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); - if(ecm_ctx == NULL) + ue_ctx_t * ue_ctx = m_s1ap->find_ue_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); + if(ue_ctx == NULL) { - m_s1ap_log->info("No UE ECM context to release found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); - m_s1ap_log->console("No UE ECM context to release found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + m_s1ap_log->info("No UE context to release found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + m_s1ap_log->console("No UE context to release found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); return false; } + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; //Delete user plane context at the SPGW (but keep GTP-C connection). if (ecm_ctx->state == ECM_STATE_CONNECTED) @@ -284,23 +282,27 @@ s1ap_ctx_mngmt_proc::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECON m_s1ap_log->console("There are active E-RABs, send release access mearers request"); m_s1ap_log->info("There are active E-RABs, send release access mearers request"); m_mme_gtpc->send_release_access_bearers_request(ecm_ctx->imsi); + //The handle_releease_access_bearers_response function will make sure to mark E-RABS DEACTIVATED + //It will release the UEs downstream S1-u and keep the upstream S1-U connection active. } else { //No ECM Context to release m_s1ap_log->info("UE is not ECM connected. No need to release S1-U. MME UE S1AP Id %d\n", mme_ue_s1ap_id); m_s1ap_log->console("UE is not ECM connected. No need to release S1-U. MME UE S1AP Id %d\n", mme_ue_s1ap_id); + //Make sure E-RABS are merked as DEACTIVATED. + for(int i=0;ierabs_ctx[i].state = ERAB_DEACTIVATED; + } } - //m_s1ap->delete_ue_ctx(ue_ctx); - for(int i=0;ierabs_ctx[i].state = ERAB_DEACTIVATED; - } + //Delete UE context - ecm_ctx->state = ECM_STATE_DISCONNECTED; + ecm_ctx->state = ECM_STATE_IDLE; + ecm_ctx->enb_ue_s1ap_id = 0; ecm_ctx->mme_ue_s1ap_id = 0; - m_s1ap_log->info("UE ECM Disconnected.\n"); - m_s1ap_log->console("Deleted UE ECM Context.\n"); + m_s1ap_log->info("UE is ECM IDLE.\n"); + m_s1ap_log->console("UE is ECM IDLE.\n"); return true; } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 2227cddda..0cde1635d 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -140,14 +140,16 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA bool mac_valid = false; //Get UE ECM context - ue_ecm_ctx_t *ue_ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); - if(ue_ecm_ctx == NULL) + ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); + if(ue_ctx == NULL) { m_s1ap_log->warning("Received uplink NAS, but could not find UE ECM context. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); return false; } m_s1ap_log->debug("Received uplink NAS and found UE ECM context. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; //Parse NAS message header srslte::byte_buffer_t *nas_msg = m_pool->allocate(); @@ -161,15 +163,13 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA //Find UE EMM context if message is security protected. if(sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS) { - //Get EMM context to do integrity check/de-chiphering - ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); - if(ue_emm_ctx == NULL) + //Make sure EMM context is set-up, to do integrity check/de-chiphering + if(emm_ctx->imsi == 0) { //No EMM context found. //Perhaps a temporary context is being created? - //This can happen with integrity protected identity reponse and authentication response messages - if( !(msg_type == LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE && sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY) && - !(msg_type == LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE && sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY)) + //This can happen with integrity protected identity reponse messages + if( !(msg_type == LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE && sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY)) { m_s1ap_log->warning("Uplink NAS: could not find security context for integrity protected message. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); m_pool->deallocate(nas_msg); @@ -191,12 +191,12 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA case LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE: m_s1ap_log->info("Uplink NAS: Received Identity Response\n"); m_s1ap_log->console("Uplink NAS: Received Identity Response\n"); - handle_identity_response(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); + handle_identity_response(nas_msg, ue_ctx, reply_buffer, reply_flag); break; case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_RESPONSE: m_s1ap_log->info("Uplink NAS: Received Authentication Response\n"); m_s1ap_log->console("Uplink NAS: Received Authentication Response\n"); - handle_nas_authentication_response(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); + handle_nas_authentication_response(nas_msg, ue_ctx, reply_buffer, reply_flag); break; default: m_s1ap_log->warning("Unhandled Plain NAS message 0x%x\n", msg_type ); @@ -205,14 +205,7 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA return false; } //Increment UL NAS count. - ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); - if(ue_emm_ctx == NULL) - { - m_s1ap_log->warning("Could not find UE EMM context in ", msg_type ); - m_pool->deallocate(nas_msg); - return false; - } - ue_emm_ctx->security_ctxt.ul_nas_count++; + emm_ctx->security_ctxt.ul_nas_count++; } else if(sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_WITH_NEW_EPS_SECURITY_CONTEXT || sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED_WITH_NEW_EPS_SECURITY_CONTEXT) { @@ -220,11 +213,11 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA case LIBLTE_MME_MSG_TYPE_SECURITY_MODE_COMPLETE: m_s1ap_log->info("Uplink NAS: Received Security Mode Complete\n"); m_s1ap_log->console("Uplink NAS: Received Security Mode Complete\n"); - ue_emm_ctx->security_ctxt.ul_nas_count = 0; - ue_emm_ctx->security_ctxt.dl_nas_count = 0; - mac_valid = integrity_check(ue_emm_ctx,nas_msg); + emm_ctx->security_ctxt.ul_nas_count = 0; + emm_ctx->security_ctxt.dl_nas_count = 0; + mac_valid = integrity_check(emm_ctx,nas_msg); if(mac_valid){ - handle_nas_security_mode_complete(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); + handle_nas_security_mode_complete(nas_msg, ue_ctx, reply_buffer, reply_flag); } else { m_s1ap_log->warning("Invalid MAC in Security Mode Command Complete message.\n" ); } @@ -237,7 +230,7 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA else if(sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY || sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED) { //Integrity protected NAS message, possibly chiphered. - ue_emm_ctx->security_ctxt.ul_nas_count++; + emm_ctx->security_ctxt.ul_nas_count++; mac_valid = integrity_check(ue_emm_ctx,nas_msg); if(!mac_valid){ m_s1ap_log->warning("Invalid MAC in NAS message type 0x%x.\n", msg_type); @@ -248,20 +241,20 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA case LIBLTE_MME_MSG_TYPE_ATTACH_COMPLETE: m_s1ap_log->info("Uplink NAS: Received Attach Complete\n"); m_s1ap_log->console("Uplink NAS: Received Attach Complete\n"); - handle_nas_attach_complete(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); + handle_nas_attach_complete(nas_msg, ue_ctx, reply_buffer, reply_flag); break; case LIBLTE_MME_MSG_TYPE_ESM_INFORMATION_RESPONSE: m_s1ap_log->info("Uplink NAS: Received ESM Information Response\n"); m_s1ap_log->console("Uplink NAS: Received ESM Information Response\n"); - handle_esm_information_response(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); + handle_esm_information_response(nas_msg, ue_ctx, reply_buffer, reply_flag); break; case LIBLTE_MME_MSG_TYPE_TRACKING_AREA_UPDATE_REQUEST: m_s1ap_log->info("UL NAS: Tracking Area Update Request\n"); - handle_tracking_area_update_request(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); + handle_tracking_area_update_request(nas_msg, ue_ctx, reply_buffer, reply_flag); break; case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_FAILURE: m_s1ap_log->info("Uplink NAS: Authentication Failure\n"); - handle_authentication_failure(nas_msg, ue_ecm_ctx, reply_buffer, reply_flag); + handle_authentication_failure(nas_msg, ue_ctx, reply_buffer, reply_flag); break; default: m_s1ap_log->warning("Unhandled NAS integrity protected message 0x%x\n", msg_type ); @@ -281,8 +274,8 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA if(*reply_flag == true) { if(ue_emm_ctx != NULL){ - m_s1ap_log->console("DL NAS: Sent Downlink NAs Message. DL NAS Count=%d, UL NAS count=%d\n",ue_emm_ctx->security_ctxt.dl_nas_count,ue_emm_ctx->security_ctxt.ul_nas_count ); - m_s1ap_log->info("DL NAS: Sent Downlink NAS message. DL NAS Count=%d, UL NAS count=%d\n",ue_emm_ctx->security_ctxt.dl_nas_count, ue_emm_ctx->security_ctxt.ul_nas_count); + m_s1ap_log->console("DL NAS: Sent Downlink NAs Message. DL NAS Count=%d, UL NAS count=%d\n",emm_ctx->security_ctxt.dl_nas_count,emm_ctx->security_ctxt.ul_nas_count ); + m_s1ap_log->info("DL NAS: Sent Downlink NAS message. DL NAS Count=%d, UL NAS count=%d\n",emm_ctx->security_ctxt.dl_nas_count, emm_ctx->security_ctxt.ul_nas_count); } else{ m_s1ap_log->console("DL NAS: Sent Downlink NAS Message\n"); @@ -290,7 +283,6 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA } } m_pool->deallocate(nas_msg); - return true; } @@ -353,54 +345,54 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, uint8_t rand[16]; uint8_t xres[8]; - - ue_emm_ctx_t ue_emm_ctx; - ue_ecm_ctx_t ue_ecm_ctx; + ue_ctx_t ue_ctx; + ue_emm_ctx_t *emm_ctx = &ue_ctx.emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx.ecm_ctx; //Set UE's EMM context - ue_emm_ctx.imsi = 0; + emm_ctx->imsi = 0; for(int i=0;i<=14;i++){ - ue_emm_ctx.imsi += attach_req.eps_mobile_id.imsi[i]*std::pow(10,14-i); + emm_ctx->imsi += attach_req.eps_mobile_id.imsi[i]*std::pow(10,14-i); } - ue_emm_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); - ue_emm_ctx.state = EMM_STATE_DEREGISTERED; + emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + emm_ctx->state = EMM_STATE_DEREGISTERED; //Save UE network capabilities - memcpy(&ue_emm_ctx.security_ctxt.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); - ue_emm_ctx.security_ctxt.ms_network_cap_present = attach_req.ms_network_cap_present; + memcpy(&emm_ctx->security_ctxt.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); + emm_ctx->security_ctxt.ms_network_cap_present = attach_req.ms_network_cap_present; if(attach_req.ms_network_cap_present) { - memcpy(&ue_emm_ctx.security_ctxt.ms_network_cap, &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); + memcpy(&emm_ctx->security_ctxt.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 - ue_emm_ctx.procedure_transaction_id = pdn_con_req.proc_transaction_id; + emm_ctx->procedure_transaction_id = pdn_con_req.proc_transaction_id; //Initialize NAS count - ue_emm_ctx.security_ctxt.ul_nas_count = 0; - ue_emm_ctx.security_ctxt.dl_nas_count = 0; - + emm_ctx->security_ctxt.ul_nas_count = 0; + emm_ctx->security_ctxt.dl_nas_count = 0; //Set UE ECM context - ue_ecm_ctx.imsi = ue_emm_ctx.imsi; - ue_ecm_ctx.mme_ue_s1ap_id = ue_emm_ctx.mme_ue_s1ap_id; + ecm_ctx->imsi = emm_ctx->imsi; + ecm_ctx->mme_ue_s1ap_id = emm_ctx->mme_ue_s1ap_id; + //Set eNB information - ue_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; - memcpy(&ue_ecm_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); //Save whether secure ESM information transfer is necessary - ue_ecm_ctx.eit = pdn_con_req.esm_info_transfer_flag_present; + ecm_ctx->eit = pdn_con_req.esm_info_transfer_flag_present; //Initialize E-RABs for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) { - ue_ecm_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED; - ue_ecm_ctx.erabs_ctx[i].erab_id = i; + ecm_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; + ecm_ctx->erabs_ctx[i].erab_id = i; } //Log Attach Request information - m_s1ap_log->console("Attach request -- IMSI: %015lu\n", ue_emm_ctx.imsi); - m_s1ap_log->info("Attach request -- IMSI: %015lu\n", ue_emm_ctx.imsi); - m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ue_ecm_ctx.enb_ue_s1ap_id, ue_ecm_ctx.mme_ue_s1ap_id); - m_s1ap_log->info("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ue_ecm_ctx.enb_ue_s1ap_id, ue_ecm_ctx.mme_ue_s1ap_id); + m_s1ap_log->console("Attach request -- IMSI: %015lu\n", emm_ctx->imsi); + m_s1ap_log->info("Attach request -- IMSI: %015lu\n", emm_ctx->imsi); + m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); + m_s1ap_log->info("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); m_s1ap_log->console("Attach request -- Attach type: %d\n", attach_req.eps_attach_type); m_s1ap_log->info("Attach request -- Attach type: %d\n", attach_req.eps_attach_type); @@ -428,21 +420,20 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, m_s1ap_log->console("PDN Connectivity Request -- ESM Information Transfer requested: %s\n", pdn_con_req.esm_info_transfer_flag_present ? "true" : "false"); //Save attach request type - ue_emm_ctx.attach_type = attach_req.eps_attach_type; + emm_ctx->attach_type = attach_req.eps_attach_type; //Get Authentication Vectors from HSS - if(!m_hss->gen_auth_info_answer(ue_emm_ctx.imsi, ue_emm_ctx.security_ctxt.k_asme, autn, rand, ue_emm_ctx.security_ctxt.xres)) + if(!m_hss->gen_auth_info_answer(emm_ctx->imsi, emm_ctx->security_ctxt.k_asme, autn, rand, emm_ctx->security_ctxt.xres)) { - m_s1ap_log->console("User not found. IMSI %015lu\n",ue_emm_ctx.imsi); - m_s1ap_log->info("User not found. IMSI %015lu\n",ue_emm_ctx.imsi); + m_s1ap_log->console("User not found. IMSI %015lu\n",emm_ctx->imsi); + m_s1ap_log->info("User not found. IMSI %015lu\n",emm_ctx->imsi); return false; } - m_s1ap->add_new_ue_emm_ctx(ue_emm_ctx); - m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); + m_s1ap->add_new_ue_ctx(ue_ctx); //Pack NAS Authentication Request in Downlink NAS Transport msg - pack_authentication_request(reply_buffer, ue_ecm_ctx.enb_ue_s1ap_id, ue_ecm_ctx.mme_ue_s1ap_id, autn, rand); + pack_authentication_request(reply_buffer, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id, autn, rand); //Send reply to eNB *reply_flag = true; @@ -542,7 +533,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, m_s1ap_log->console("Could not find M-TMSI=0x%x. Sending ID request\n",m_tmsi); m_s1ap_log->info("Could not find M-TMSI=0x%x. Sending Id Request\n", m_tmsi); - m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); + //m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); //We do not know the IMSI of the UE yet //This will be removed when the identity response is received @@ -558,45 +549,48 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, m_s1ap_log->console("Attach Request -- Found M-TMSI: %d\n",m_tmsi); m_s1ap_log->console("Attach Request -- IMSI: %d\n",it->second); //Get UE EMM context - ue_emm_ctx_t *ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(it->second); - if(ue_emm_ctx!=NULL) + ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_imsi(it->second); + if(ue_ctx!=NULL) { - m_s1ap_log->console("Found UE context. IMSI: %015lu\n",ue_emm_ctx->imsi); + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + m_s1ap_log->console("Found UE context. IMSI: %015lu\n",emm_ctx->imsi); + //Check NAS integrity bool msg_valid = false; - ue_emm_ctx->security_ctxt.ul_nas_count++; - msg_valid = integrity_check(ue_emm_ctx,nas_msg); + emm_ctx->security_ctxt.ul_nas_count++; + msg_valid = integrity_check(emm_ctx,nas_msg); if(msg_valid == true) { //Create new MME UE S1AP Identity - ue_emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); //Set EMM as de-registered - ue_emm_ctx->state = EMM_STATE_DEREGISTERED; + emm_ctx->state = EMM_STATE_DEREGISTERED; //Save Attach type - ue_emm_ctx->attach_type = attach_req.eps_attach_type; - //Create UE ECM context - ue_ecm_ctx_t ue_ecm_ctx; + emm_ctx->attach_type = attach_req.eps_attach_type; //Set UE ECM context - ue_ecm_ctx.imsi = ue_emm_ctx->imsi; - ue_ecm_ctx.mme_ue_s1ap_id = ue_emm_ctx->mme_ue_s1ap_id; + ecm_ctx->imsi = ecm_ctx->imsi; + ecm_ctx->mme_ue_s1ap_id = ecm_ctx->mme_ue_s1ap_id; + //Set eNB information - ue_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; - memcpy(&ue_ecm_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); //Save whether secure ESM information transfer is necessary - ue_ecm_ctx.eit = pdn_con_req.esm_info_transfer_flag_present; + ecm_ctx->eit = pdn_con_req.esm_info_transfer_flag_present; //Initialize E-RABs for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) { - ue_ecm_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED; - ue_ecm_ctx.erabs_ctx[i].erab_id = i; + ecm_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; + ecm_ctx->erabs_ctx[i].erab_id = i; } - m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); + + //m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); //Create session request m_s1ap_log->console("GUTI Attach -- NAS Integrity OK."); - m_mme_gtpc->send_create_session_request(ue_emm_ctx->imsi); + m_mme_gtpc->send_create_session_request(emm_ctx->imsi); *reply_flag = false; //No reply needed return true; } @@ -649,8 +643,8 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, return true; } - ue_emm_ctx_t *emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(it->second); - if(emm_ctx == NULL || emm_ctx->state != EMM_STATE_REGISTERED) + ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_imsi(it->second); + if(ue_ctx == NULL || ue_ctx->emm_ctx.state != EMM_STATE_REGISTERED) { m_s1ap_log->console("UE is not EMM-Registered.\n"); m_s1ap_log->error("UE is not EMM-Registered.\n"); @@ -658,80 +652,68 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, *reply_flag = true; return true; } + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + emm_ctx->security_ctxt.ul_nas_count++; mac_valid = short_integrity_check(emm_ctx,nas_msg); if(mac_valid) { m_s1ap_log->console("Service Request -- Short MAC valid\n"); m_s1ap_log->info("Service Request -- Short MAC valid\n"); - ue_ecm_ctx_t *ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(emm_ctx->mme_ue_s1ap_id); - if(ecm_ctx == NULL) + if(ecm_ctx->state == ECM_STATE_CONNECTED) { - m_s1ap_log->console("UE ECM context is not initialized.\n"); - m_s1ap_log->error("UE ECM context is not initialized.\n"); - pack_service_reject(reply_buffer, LIBLTE_MME_EMM_CAUSE_IMPLICITLY_DETACHED, enb_ue_s1ap_id); - *reply_flag = true; - return true; + m_s1ap_log->error("Service Request -- User is ECM CONNECTED\n"); + + //Service request to Connected UE. + //Set eNB UE S1ap identity + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + m_s1ap_log->console("Service Request -- eNB UE S1AP Id %d \n", enb_ue_s1ap_id); + m_s1ap_log->info("Service Request -- eNB UE S1AP Id %d\n ", enb_ue_s1ap_id); + + //Delete eNB context and connect. + m_s1ap_log->console("Service Request -- User has ECM context already\n"); + m_s1ap_log->info("Service Request -- User has ECM context already\n"); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); + //int default_bearer_id = 5; + //m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[default_bearer_id]); + //FIXME Send Modify context request OR send ctx release command and wait for the reply. } - else + else if(ecm_ctx->state == ECM_STATE_IDLE) { - if(ecm_ctx->state == ECM_STATE_CONNECTED) + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + + //UE not connect. Connect normally. + m_s1ap_log->console("Service Request -- User is ECM DISCONNECTED\n"); + m_s1ap_log->info("Service Request -- User is ECM DISCONNECTED\n"); + //Create ECM context + ecm_ctx->imsi = emm_ctx->imsi; + ecm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + emm_ctx->mme_ue_s1ap_id = ecm_ctx->mme_ue_s1ap_id; + //Set eNB information + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + + //Save whether secure ESM information transfer is necessary + ecm_ctx->eit = false; + + //Initialize E-RABs + for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) { - m_s1ap_log->error("Service Request -- User is ECM CONNECTED\n"); - - //Service request to Connected UE. - //Set eNB UE S1ap identity - ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; - m_s1ap_log->console("Service Request -- eNB UE S1AP Id %d \n", enb_ue_s1ap_id); - m_s1ap_log->info("Service Request -- eNB UE S1AP Id %d\n ", enb_ue_s1ap_id); - - //Delete eNB context and connect. - m_s1ap_log->console("Service Request -- User has ECM context already\n"); - m_s1ap_log->info("Service Request -- User has ECM context already\n"); - m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); - //int default_bearer_id = 5; - //m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[default_bearer_id]); - //FIXME Send Modify context request OR send ctx release command and wait for the reply. - + ecm_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; + ecm_ctx->erabs_ctx[i].erab_id = i; } - else if(ecm_ctx->state == ECM_STATE_DISCONNECTED) - { - ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; - - //UE not connect. Connect normally. - m_s1ap_log->console("Service Request -- User is ECM DISCONNECTED\n"); - m_s1ap_log->info("Service Request -- User is ECM DISCONNECTED\n"); - //Create ECM context - ecm_ctx->imsi = emm_ctx->imsi; - ecm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); - emm_ctx->mme_ue_s1ap_id = ecm_ctx->mme_ue_s1ap_id; - //Set eNB information - ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; - memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); - - //Save whether secure ESM information transfer is necessary - ecm_ctx->eit = false; - //Initialize E-RABs - for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) - { - ue_ecm_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED; - ue_ecm_ctx.erabs_ctx[i].erab_id = i; - } - ecm_ctx = m_s1ap->find_ue_ecm_ctx_from_mme_ue_s1ap_id(emm_ctx->mme_ue_s1ap_id); - - //Re-generate K_eNB - liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); - m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); - m_s1ap_log->console("UE Ctr TEID %d\n", emm_ctx->sgw_ctrl_fteid.teid); - m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx,&ecm_ctx->erabs_ctx[5]); - - } - else - { - m_s1ap_log->console("ECM context is un-initialized.\n"); - m_s1ap_log->error("ECM context is un-initialized.\n"); - } + //Re-generate K_eNB + liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); + m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); + m_s1ap_log->console("UE Ctr TEID %d\n", emm_ctx->sgw_ctrl_fteid.teid); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx,&ecm_ctx->erabs_ctx[5]); + } + else + { + m_s1ap_log->console("ECM context is un-initialized.\n"); + m_s1ap_log->error("ECM context is un-initialized.\n"); } } else @@ -743,19 +725,15 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, return true; } bool -s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag) +s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag) { LIBLTE_MME_AUTHENTICATION_RESPONSE_MSG_STRUCT auth_resp; bool ue_valid=true; - ue_emm_ctx_t *ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); - if(ue_emm_ctx == NULL) - { - m_s1ap_log->error("Authentication Response -- Could not find UE EMM context.\n"); - return false; - } - m_s1ap_log->console("Authentication Response -- IMSI %015lu\n", ue_emm_ctx->imsi); + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + m_s1ap_log->console("Authentication Response -- IMSI %015lu\n", emm_ctx->imsi); //Get NAS authentication response LIBLTE_ERROR_ENUM err = liblte_mme_unpack_authentication_response_msg((LIBLTE_BYTE_MSG_STRUCT *) nas_msg, &auth_resp); @@ -772,26 +750,19 @@ s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *na for(int i=0; i<8;i++) { - if(auth_resp.res[i] != ue_emm_ctx->security_ctxt.xres[i]) + if(auth_resp.res[i] != emm_ctx->security_ctxt.xres[i]) { ue_valid = false; } } if(!ue_valid) { - std::cout<security_ctxt.xres[i]; - } - std::cout<info_hex(emm_ctx->security_ctxt.xres,8, "XRES"); m_s1ap_log->console("UE Authentication Rejected.\n"); m_s1ap_log->warning("UE Authentication Rejected.\n"); //Send back Athentication Reject - pack_authentication_reject(reply_buffer, ue_ecm_ctx->enb_ue_s1ap_id, ue_ecm_ctx->mme_ue_s1ap_id); + pack_authentication_reject(reply_buffer, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); *reply_flag = true; m_s1ap_log->console("Downlink NAS: Sending Authentication Reject.\n"); return false; @@ -801,7 +772,7 @@ s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *na m_s1ap_log->console("UE Authentication Accepted.\n"); m_s1ap_log->info("UE Authentication Accepted.\n"); //Send Security Mode Command - pack_security_mode_command(reply_buffer, ue_emm_ctx, ue_ecm_ctx); + pack_security_mode_command(reply_buffer, emm_ctx, ecm_ctx); *reply_flag = true; m_s1ap_log->console("Downlink NAS: Sending NAS Security Mode Command.\n"); } @@ -809,15 +780,11 @@ s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *na } bool -s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) +s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) { - ue_emm_ctx_t *ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); - if(ue_emm_ctx == NULL) - { - m_s1ap_log->error("Could not find UE's EMM context\n"); - return false; - } + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; LIBLTE_MME_SECURITY_MODE_COMPLETE_MSG_STRUCT sm_comp; @@ -834,11 +801,11 @@ s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas m_s1ap_log->warning("IMEI-SV present but not handled"); } - m_s1ap_log->info("Security Mode Command Complete -- IMSI: %lu\n", ue_ecm_ctx->imsi); - m_s1ap_log->console("Security Mode Command Complete -- IMSI: %lu\n", ue_ecm_ctx->imsi); - if(ue_ecm_ctx->eit == true) + m_s1ap_log->info("Security Mode Command Complete -- IMSI: %lu\n", emm_ctx->imsi); + m_s1ap_log->console("Security Mode Command Complete -- IMSI: %lu\n", emm_ctx->imsi); + if(ecm_ctx->eit == true) { - pack_esm_information_request(reply_buffer, ue_emm_ctx, ue_ecm_ctx); + pack_esm_information_request(reply_buffer, emm_ctx, ecm_ctx); m_s1ap_log->console("Sending ESM information request\n"); m_s1ap_log->info("Sending ESM information request\n"); *reply_flag = true; @@ -847,14 +814,14 @@ s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas { //FIXME The packging of GTP-C messages is not ready. //This means that GTP-U tunnels are created with function calls, as opposed to GTP-C. - m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi); + m_mme_gtpc->send_create_session_request(emm_ctx->imsi); *reply_flag = false; //No reply needed } return true; } bool -s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t *ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) +s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { LIBLTE_MME_ATTACH_COMPLETE_MSG_STRUCT attach_comp; @@ -877,11 +844,8 @@ s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, u return false; } - ue_emm_ctx_t *emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ecm_ctx->imsi); - if(emm_ctx == NULL) - { - m_s1ap_log->error("Received Attach complete, but could not find UE's EMM Context.\n"); - } + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; m_s1ap_log->console("Unpacked Attached Complete Message. IMSI %d\n", emm_ctx->imsi); m_s1ap_log->console("Unpacked Activate Default EPS Bearer message. EPS Bearer id %d\n",act_bearer.eps_bearer_id); @@ -894,10 +858,10 @@ s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, u if(emm_ctx->state == EMM_STATE_DEREGISTERED) { //Attach requested from attach request - m_mme_gtpc->send_modify_bearer_request(ecm_ctx->imsi, &ecm_ctx->erabs_ctx[act_bearer.eps_bearer_id]); + m_mme_gtpc->send_modify_bearer_request(emm_ctx->imsi, &ecm_ctx->erabs_ctx[act_bearer.eps_bearer_id]); //Send reply to eNB m_s1ap_log->console("Packing EMM infromationi\n"); - *reply_flag = pack_emm_information(ecm_ctx, reply_msg); + *reply_flag = pack_emm_information(ue_ctx, reply_msg); m_s1ap_log->console("Sending EMM infromation, bytes %d\n",reply_msg->N_bytes); m_s1ap_log->info("Sending EMM infromation\n"); } @@ -906,7 +870,7 @@ s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, u } bool -s1ap_nas_transport::handle_esm_information_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) +s1ap_nas_transport::handle_esm_information_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { LIBLTE_MME_ESM_INFORMATION_RESPONSE_MSG_STRUCT esm_info_resp; @@ -930,12 +894,12 @@ s1ap_nas_transport::handle_esm_information_response(srslte::byte_buffer_t *nas_m //FIXME The packging of GTP-C messages is not ready. //This means that GTP-U tunnels are created with function calls, as opposed to GTP-C. - m_mme_gtpc->send_create_session_request(ue_ecm_ctx->imsi); + m_mme_gtpc->send_create_session_request(ue_ctx->emm_ctx.imsi); return true; } bool -s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) +s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { uint8_t autn[16]; uint8_t rand[16]; @@ -953,40 +917,42 @@ s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ imsi += id_resp.mobile_id.imsi[i]*std::pow(10,14-i); } + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; //Check if EMM context already exists - ue_emm_ctx_t *ue_tmp_ptr = m_s1ap->find_ue_emm_ctx_from_imsi(imsi); - if(ue_tmp_ptr != NULL) - { - m_s1ap_log->warning("Unkonw GUTI, but UE's EMM context present.\n"); - m_s1ap->delete_ue_emm_ctx(imsi); - } + //ue_ctx_t *ue_tmp_ptr = m_s1ap->find_ue_ctx_from_imsi(imsi); + //if(ue_tmp_ptr != NULL) + //{ + // m_s1ap_log->warning("Unkonw GUTI, but UE's EMM context present.\n"); + // m_s1ap->delete_ue_emm_ctx(imsi); + //} m_s1ap_log->info("Id Response -- IMSI: %015lu\n", imsi); m_s1ap_log->console("Id Response -- IMSI: %015lu\n", imsi); - ue_ecm_ctx->imsi = imsi; + ecm_ctx->imsi = imsi; //Get UE EMM context - ue_emm_ctx_t ue_emm_ctx; - if(m_s1ap->get_tmp_ue_emm_ctx(ue_ecm_ctx->mme_ue_s1ap_id, &ue_emm_ctx) == false) - { - m_s1ap_log->error("Could not find UE's temporary EMM context. MME UE S1AP Id: %d\n",ue_ecm_ctx->mme_ue_s1ap_id); - return false; - } - ue_emm_ctx.imsi=imsi; + //if(m_s1ap->get_tmp_ue_emm_ctx(ue_ecm_ctx->mme_ue_s1ap_id, &ue_emm_ctx) == false) + //{ + // m_s1ap_log->error("Could not find UE's temporary EMM context. MME UE S1AP Id: %d\n",ue_ecm_ctx->mme_ue_s1ap_id); + // return false; + //} + emm_ctx->imsi=imsi; //Get Authentication Vectors from HSS - if(!m_hss->gen_auth_info_answer(imsi, ue_emm_ctx.security_ctxt.k_asme, autn, rand, ue_emm_ctx.security_ctxt.xres)) + if(!m_hss->gen_auth_info_answer(imsi, emm_ctx->security_ctxt.k_asme, autn, rand, emm_ctx->security_ctxt.xres)) { m_s1ap_log->console("User not found. IMSI %015lu\n",imsi); m_s1ap_log->info("User not found. IMSI %015lu\n",imsi); return false; } + //Store UE EMM context - m_s1ap->add_new_ue_emm_ctx(ue_emm_ctx); + //m_s1ap->add_new_ue_emm_ctx(ue_emm_ctx); //Pack NAS Authentication Request in Downlink NAS Transport msg - pack_authentication_request(reply_msg, ue_ecm_ctx->enb_ue_s1ap_id, ue_ecm_ctx->mme_ue_s1ap_id, autn, rand); + pack_authentication_request(reply_msg, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id, autn, rand); //Send reply to eNB *reply_flag = true; @@ -999,7 +965,7 @@ s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ bool -s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) +s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { m_s1ap_log->console("Warning: Tracking Area Update Request messages not handled yet.\n"); @@ -1018,8 +984,8 @@ s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *n //Setup Dw NAS structure LIBLTE_S1AP_MESSAGE_DOWNLINKNASTRANSPORT_STRUCT *dw_nas = &init->choice.DownlinkNASTransport; dw_nas->ext=false; - dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ecm_ctx->mme_ue_s1ap_id; - dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ecm_ctx->enb_ue_s1ap_id; + dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ctx->ecm_ctx.mme_ue_s1ap_id; + dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ctx->ecm_ctx.enb_ue_s1ap_id; dw_nas->HandoverRestrictionList_present=false; dw_nas->SubscriberProfileIDforRFP_present=false; //m_s1ap_log->console("Tracking area accept to MME-UE S1AP Id %d\n", ue_ctx->mme_ue_s1ap_id); @@ -1197,7 +1163,7 @@ s1ap_nas_transport::integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t bool -s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg, ue_ecm_ctx_t* ue_ecm_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) +s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { uint8_t autn[16]; uint8_t rand[16]; @@ -1210,12 +1176,8 @@ s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg return false; } - ue_emm_ctx_t *emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); - if(emm_ctx == NULL) - { - m_s1ap_log->error("Could not find UE EMM context\n"); - return false; - } + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; switch(auth_fail.emm_cause){ case 20: @@ -1233,22 +1195,22 @@ s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg m_s1ap_log->error("Missing fail parameter\n"); return false; } - if(!m_hss->resync_sqn(ue_ecm_ctx->imsi, auth_fail.auth_fail_param)) + if(!m_hss->resync_sqn(emm_ctx->imsi, auth_fail.auth_fail_param)) { - m_s1ap_log->console("Resynchronization failed. IMSI %015lu\n", ue_ecm_ctx->imsi); - m_s1ap_log->info("Resynchronization failed. IMSI %015lu\n", ue_ecm_ctx->imsi); + m_s1ap_log->console("Resynchronization failed. IMSI %015lu\n", emm_ctx->imsi); + m_s1ap_log->info("Resynchronization failed. IMSI %015lu\n", emm_ctx->imsi); return false; } //Get Authentication Vectors from HSS - if(!m_hss->gen_auth_info_answer(ue_ecm_ctx->imsi, emm_ctx->security_ctxt.k_asme, autn, rand, emm_ctx->security_ctxt.xres)) + if(!m_hss->gen_auth_info_answer(emm_ctx->imsi, emm_ctx->security_ctxt.k_asme, autn, rand, emm_ctx->security_ctxt.xres)) { - m_s1ap_log->console("User not found. IMSI %015lu\n", ue_ecm_ctx->imsi); - m_s1ap_log->info("User not found. IMSI %015lu\n", ue_ecm_ctx->imsi); + m_s1ap_log->console("User not found. IMSI %015lu\n", emm_ctx->imsi); + m_s1ap_log->info("User not found. IMSI %015lu\n", emm_ctx->imsi); return false; } //Pack NAS Authentication Request in Downlink NAS Transport msg - pack_authentication_request(reply_msg, ue_ecm_ctx->enb_ue_s1ap_id, ue_ecm_ctx->mme_ue_s1ap_id, autn, rand); + pack_authentication_request(reply_msg, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id, autn, rand); //Send reply to eNB *reply_flag = true; @@ -1764,10 +1726,12 @@ s1ap_nas_transport::pack_identity_request(srslte::byte_buffer_t *reply_msg, uint } bool -s1ap_nas_transport::pack_emm_information( ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte_buffer_t *reply_msg) +s1ap_nas_transport::pack_emm_information( ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_msg) { srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; //Setup initiating message LIBLTE_S1AP_S1AP_PDU_STRUCT tx_pdu; bzero(&tx_pdu, sizeof(LIBLTE_S1AP_S1AP_PDU_STRUCT)); @@ -1782,8 +1746,8 @@ s1ap_nas_transport::pack_emm_information( ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte //Setup Dw NAS structure LIBLTE_S1AP_MESSAGE_DOWNLINKNASTRANSPORT_STRUCT *dw_nas = &init->choice.DownlinkNASTransport; dw_nas->ext=false; - dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ue_ecm_ctx->mme_ue_s1ap_id;//FIXME Change name - dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ecm_ctx->enb_ue_s1ap_id; + dw_nas->MME_UE_S1AP_ID.MME_UE_S1AP_ID = ecm_ctx->mme_ue_s1ap_id;//FIXME Change name + dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ecm_ctx->enb_ue_s1ap_id; dw_nas->HandoverRestrictionList_present=false; dw_nas->SubscriberProfileIDforRFP_present=false; @@ -1799,13 +1763,9 @@ s1ap_nas_transport::pack_emm_information( ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte emm_info.utc_and_local_time_zone_present = false; emm_info.net_dst_present = false; - ue_emm_ctx_t *ue_emm_ctx = m_s1ap->find_ue_emm_ctx_from_imsi(ue_ecm_ctx->imsi); - if(ue_emm_ctx ==NULL) - return false; - uint8_t sec_hdr_type =2; - ue_emm_ctx->security_ctxt.dl_nas_count++; - LIBLTE_ERROR_ENUM err = liblte_mme_pack_emm_information_msg(&emm_info, sec_hdr_type, ue_emm_ctx->security_ctxt.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); + emm_ctx->security_ctxt.dl_nas_count++; + LIBLTE_ERROR_ENUM err = liblte_mme_pack_emm_information_msg(&emm_info, sec_hdr_type, emm_ctx->security_ctxt.dl_nas_count, (LIBLTE_BYTE_MSG_STRUCT *) nas_buffer); if(err != LIBLTE_SUCCESS) { m_s1ap_log->error("Error packing EMM Information\n"); @@ -1814,8 +1774,8 @@ s1ap_nas_transport::pack_emm_information( ue_ecm_ctx_t *ue_ecm_ctx, srslte::byte } uint8_t mac[4]; - srslte::security_128_eia1 (&ue_emm_ctx->security_ctxt.k_nas_int[16], - ue_emm_ctx->security_ctxt.dl_nas_count, + srslte::security_128_eia1 (&emm_ctx->security_ctxt.k_nas_int[16], + emm_ctx->security_ctxt.dl_nas_count, 0, SECURITY_DIRECTION_DOWNLINK, &nas_buffer->msg[5], From 7d37c6b9c32887245ad9d56f986ab7615f130ba4 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 14 Mar 2018 13:36:20 +0000 Subject: [PATCH 079/143] Continuing to fix compilation issues. Starting to change S1AP to use the new functions to store ctx. --- srsepc/hdr/mme/s1ap.h | 8 +++++- srsepc/src/mme/s1ap.cc | 62 ++++++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 52d435fbd..a19402632 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -66,7 +66,6 @@ public: int get_s1_mme(); void delete_enb_ctx(int32_t assoc_id); - void release_ues_ecm_ctx_in_enb(uint16_t enb_id); bool handle_s1ap_rx_pdu(srslte::byte_buffer_t *pdu, struct sctp_sndrcvinfo *enb_sri); bool handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri); @@ -82,9 +81,16 @@ public: void add_new_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo* enb_sri); void add_new_ue_ctx(const ue_ctx_t &ue_ctx); + bool add_ue_ctx_to_imsi_map(const ue_ctx_t *ue_ctx); + bool add_ue_ctx_to_mme_ue_s1ap_id_map(const ue_ctx_t *ue_ctx); + ue_ctx_t* find_ue_ctx_from_imsi(uint64_t imsi); ue_ctx_t* find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id); + bool release_ue_ecm_ctx(uint32_t mme_ue_s1ap_id); + void release_ues_ecm_ctx_in_enb(uint16_t enb_id); + bool delete_ue_ctx(uint64_t imsi); + //ue_ctx_t* find_ue_ctx(uint32_t mme_ue_s1ap_id); //void add_new_ue_ctx(const ue_ctx_t &ue_ctx); diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index e59740299..a541f00e3 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -346,7 +346,7 @@ s1ap::delete_enb_ctx(int32_t assoc_id) //UE Context Management -void +/*void s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) { std::map::iterator ctx_it = m_imsi_to_ue_ctx.find(ue_ctx.emm_ctx.imsi); @@ -382,7 +382,7 @@ s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) it_ue_id->second.insert(new_ctx->ecm_ctx.mme_ue_s1ap_id); return; } - +*/ bool s1ap::add_ue_ctx_to_imsi_map(const ue_ctx_t *ue_ctx) { @@ -394,8 +394,8 @@ s1ap::add_ue_ctx_to_imsi_map(const ue_ctx_t *ue_ctx) } if(ue_ctx->ecm_ctx.mme_ue_s1ap_id != 0) { - std::map::iterator ctx_it2 = m_mme_ue_s1ap_id_to_ue_ctx.find(ue_ctx.ecm_ctx.mme_ue_s1ap_id); - if(ctx_it2 != m_mme_ue_s1ap_id_to_imsi.end() && ctx_it2->second != ue_ctx) + std::map::iterator ctx_it2 = m_mme_ue_s1ap_id_to_ue_ctx.find(ue_ctx->ecm_ctx.mme_ue_s1ap_id); + if(ctx_it2 != m_mme_ue_s1ap_id_to_ue_ctx.end() && ctx_it2->second != ue_ctx) { m_s1ap_log->error("Context identified with IMSI does not match context identified by MME UE S1AP Id.\n"); return false; @@ -409,7 +409,7 @@ s1ap::add_ue_ctx_to_mme_ue_s1ap_id_map(const ue_ctx_t *ue_ctx) { if(ue_ctx->ecm_ctx.mme_ue_s1ap_id == 0) { - m_s1ap_log->error("Could not add UE context to MME UE S1AP map. MME UE S1AP ID 0 is not valid.") + m_s1ap_log->error("Could not add UE context to MME UE S1AP map. MME UE S1AP ID 0 is not valid."); return false; } std::map::iterator ctx_it = m_mme_ue_s1ap_id_to_ue_ctx.find(ue_ctx->ecm_ctx.mme_ue_s1ap_id); @@ -420,18 +420,17 @@ s1ap::add_ue_ctx_to_mme_ue_s1ap_id_map(const ue_ctx_t *ue_ctx) } if(ue_ctx->ecm_ctx.imsi != 0) { - std::map::iterator ctx_it2 = m_mme_ue_s1ap_id_to_ue_ctx.find(ue_ctx.ecm_ctx.mme_ue_s1ap_id); - if(ctx_it2 != m_mme_ue_s1ap_id_to_imsi.end() && ctx_it2->second != ue_ctx) + std::map::iterator ctx_it2 = m_mme_ue_s1ap_id_to_ue_ctx.find(ue_ctx->ecm_ctx.mme_ue_s1ap_id); + if(ctx_it2 != m_mme_ue_s1ap_id_to_ue_ctx.end() && ctx_it2->second != ue_ctx) { m_s1ap_log->error("Context identified with MME UE S1AP Id does not match context identified by IMSI.\n"); return false; } } - - return true; } + /* void s1ap::store_tmp_ue_emm_ctx(const ue_emm_ctx_t &tmp_ue_emm_ctx) { @@ -456,12 +455,13 @@ s1ap::get_tmp_ue_emm_ctx(uint32_t mme_ue_s1ap_id, ue_emm_ctx_t* ue_emm_ptr) m_mme_ue_s1ap_id_to_tmp_ue_emm_ctx.erase(it); return true; } + */ ue_ctx_t* s1ap::find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) { std::map::iterator it = m_mme_ue_s1ap_id_to_ue_ctx.find(mme_ue_s1ap_id); - if(it == m_mme_ue_s1ap_id_to_imsi.end()) + if(it == m_mme_ue_s1ap_id_to_ue_ctx.end()) { return NULL; } @@ -494,17 +494,20 @@ s1ap::release_ues_ecm_ctx_in_enb(uint16_t enb_id) while(ue_id != ues_in_enb->second.end() ) { std::map::iterator ue_ctx = m_mme_ue_s1ap_id_to_ue_ctx.find(*ue_id); - m_s1ap_log->info("Deleting UE context. UE-MME S1AP Id: %d\n", ue_ctx->second->mme_ue_s1ap_id); - m_s1ap_log->console("Deleting UE context. UE-MME S1AP Id: %d\n", ue_ctx->second->mme_ue_s1ap_id); - - ue_set->second.erase(mme_ue_s1ap_id); + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->second->ecm_ctx; + m_s1ap_log->info("Releasing UE ECM context. UE-MME S1AP Id: %d\n", ecm_ctx->mme_ue_s1ap_id); + m_s1ap_log->console("Releasing UE ECM context. UE-MME S1AP Id: %d\n", ecm_ctx->mme_ue_s1ap_id); + ues_in_enb->second.erase(ecm_ctx->mme_ue_s1ap_id); + ecm_ctx->state = ECM_STATE_IDLE; + ecm_ctx->mme_ue_s1ap_id = 0; + ecm_ctx->enb_ue_s1ap_id = 0; } } bool s1ap::release_ue_ecm_ctx(uint32_t mme_ue_s1ap_id) { - ue_ctx_t *ue_ctx = find_ue_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id) + ue_ctx_t *ue_ctx = find_ue_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); if(ue_ctx == NULL) { m_s1ap_log->error("Cannot release UE ECM context, UE not found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); @@ -529,7 +532,7 @@ s1ap::release_ue_ecm_ctx(uint32_t mme_ue_s1ap_id) ue_set->second.erase(mme_ue_s1ap_id); //Release UE ECM context - m_mme_ue_s1ap_id_to_imsi.erase(mme_ue_s1ap_id); + m_mme_ue_s1ap_id_to_ue_ctx.erase(mme_ue_s1ap_id); ecm_ctx->state = ECM_STATE_IDLE; ecm_ctx->mme_ue_s1ap_id = 0; ecm_ctx->enb_ue_s1ap_id = 0; @@ -549,9 +552,9 @@ s1ap::delete_ue_ctx(uint64_t imsi) } //Make sure to release ECM ctx - if(ue_ctx->ecm_ctx.state == ECM_STATE_CONNECTED) + if(ue_ctx->ecm_ctx.mme_ue_s1ap_id != 0) { - release_ue_ecm_ctx(ue_ctx->ecm_state.mme_ue_s1ap_id); + release_ue_ecm_ctx(ue_ctx->ecm_ctx.mme_ue_s1ap_id); } //Delete UE context @@ -568,31 +571,32 @@ s1ap::delete_ue_ctx(uint64_t imsi) void s1ap::activate_eps_bearer(uint64_t imsi, uint8_t ebi) { - std::map::iterator emm_ctx_it = m_imsi_to_ue_emm_ctx.find(imsi); - if(emm_ctx_it == m_imsi_to_ue_emm_ctx.end()) + std::map::iterator ue_ctx_it = m_imsi_to_ue_ctx.find(imsi); + if(ue_ctx_it == m_imsi_to_ue_ctx.end()) { - m_s1ap_log->error("Could not find UE EMM context\n"); + m_s1ap_log->error("Could not activate EPS bearer: Could not find UE context\n"); return; } - uint32_t mme_ue_s1ap_id = emm_ctx_it->second->mme_ue_s1ap_id; - std::map::iterator ecm_ctx_it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_ue_s1ap_id); - if(ecm_ctx_it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) + //Make sure NAS is active + uint32_t mme_ue_s1ap_id = ue_ctx_it->second->ecm_ctx.mme_ue_s1ap_id; + std::map::iterator it = m_mme_ue_s1ap_id_to_ue_ctx.find(mme_ue_s1ap_id); + if(it == m_mme_ue_s1ap_id_to_ue_ctx.end()) { - m_s1ap_log->error("Could not find UE ECM context\n"); + m_s1ap_log->error("Could not activate EPS bearer: ECM context seems to be missing\n"); return; } - ue_ecm_ctx_t * ecm_ctx = ecm_ctx_it->second; + ue_ecm_ctx_t * ecm_ctx = &ue_ctx_it->second->ecm_ctx; if (ecm_ctx->erabs_ctx[ebi].state != ERAB_CTX_SETUP) { - m_s1ap_log->error("EPS Bearer could not be activated. MME S1AP Id %d, EPS Bearer id %d, state %d\n",mme_ue_s1ap_id,ebi,ecm_ctx->erabs_ctx[ebi].state); - m_s1ap_log->console("EPS Bearer could not be activated. MME S1AP Id %d, EPS Bearer id %d\n",mme_ue_s1ap_id,ebi,ecm_ctx->erabs_ctx[ebi].state); + 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,ecm_ctx->erabs_ctx[ebi].state); + m_s1ap_log->console("Could not be activate EPS Bearer, bearer in wrong state: MME S1AP Id %d, EPS Bearer id %d\n",mme_ue_s1ap_id,ebi,ecm_ctx->erabs_ctx[ebi].state); return; } ecm_ctx->erabs_ctx[ebi].state = ERAB_ACTIVE; ecm_ctx->state = ECM_STATE_CONNECTED; - m_s1ap_log->info("Activated EPS Bearer\n"); + m_s1ap_log->info("Activated EPS Bearer: Bearer id %d\n",ebi); return; } From 9617a63d27a638e6b15a9fa10163ea9cb6008b43 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 14 Mar 2018 15:39:43 +0000 Subject: [PATCH 080/143] continuing to change the way context is stored. Compiling now. --- srsepc/hdr/mme/s1ap.h | 5 +-- srsepc/src/mme/s1ap_nas_transport.cc | 65 ++++++++++++++++------------ 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index a19402632..b2c741d26 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -80,7 +80,6 @@ public: enb_ctx_t* find_enb_ctx(uint16_t enb_id); void add_new_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo* enb_sri); - void add_new_ue_ctx(const ue_ctx_t &ue_ctx); bool add_ue_ctx_to_imsi_map(const ue_ctx_t *ue_ctx); bool add_ue_ctx_to_mme_ue_s1ap_id_map(const ue_ctx_t *ue_ctx); @@ -102,8 +101,8 @@ public: //bool delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id); //void delete_ues_ecm_ctx_in_enb(uint16_t enb_id); - void store_tmp_ue_emm_ctx(const ue_emm_ctx_t &ue_ecm_ctx); - bool get_tmp_ue_emm_ctx(uint32_t mme_ue_s1ap_id, ue_emm_ctx_t* ue_emm_ptr); + //void store_tmp_ue_emm_ctx(const ue_emm_ctx_t &ue_ecm_ctx); + //bool get_tmp_ue_emm_ctx(uint32_t mme_ue_s1ap_id, ue_emm_ctx_t* ue_emm_ptr); uint32_t allocate_m_tmsi(uint64_t imsi); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 0cde1635d..336d84143 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -430,7 +430,11 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, return false; } - m_s1ap->add_new_ue_ctx(ue_ctx); + //Save the UE context + ue_ctx_t *new_ctx = new ue_ctx_t; + memcpy(new_ctx,&ue_ctx,sizeof(ue_ctx_t)); + m_s1ap->add_ue_ctx_to_imsi_map(new_ctx); + m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(new_ctx); //Pack NAS Authentication Request in Downlink NAS Transport msg pack_authentication_request(reply_buffer, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id, autn, rand); @@ -478,48 +482,53 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, m_s1ap_log->info("Attach Request -- Could not find M-TMSI 0x%x", m_tmsi); //Could not find IMSI from M-TMSI, send Id request - ue_emm_ctx_t tmp_ue_emm_ctx; - ue_ecm_ctx_t ue_ecm_ctx; + ue_ctx_t ue_ctx; + ue_emm_ctx_t *emm_ctx = &ue_ctx.emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx.ecm_ctx; - //Set tmp UE EMM context - tmp_ue_emm_ctx.imsi = 0; - tmp_ue_emm_ctx.state = EMM_STATE_DEREGISTERED; + //We do not know the IMSI of the UE yet + //The IMSI will be set when the identity response is received + //Set EMM ctx + emm_ctx->imsi = 0; + emm_ctx->state = EMM_STATE_DEREGISTERED; + emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); //Save UE network capabilities - memcpy(&tmp_ue_emm_ctx.security_ctxt.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); - tmp_ue_emm_ctx.security_ctxt.ms_network_cap_present = attach_req.ms_network_cap_present; + memcpy(&emm_ctx->security_ctxt.ue_network_cap, &attach_req.ue_network_cap, sizeof(LIBLTE_MME_UE_NETWORK_CAPABILITY_STRUCT)); + emm_ctx->security_ctxt.ms_network_cap_present = attach_req.ms_network_cap_present; if(attach_req.ms_network_cap_present) { - memcpy(&tmp_ue_emm_ctx.security_ctxt.ms_network_cap, &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); + memcpy(&emm_ctx->security_ctxt.ms_network_cap, &attach_req.ms_network_cap, sizeof(LIBLTE_MME_MS_NETWORK_CAPABILITY_STRUCT)); } //Initialize NAS count - tmp_ue_emm_ctx.security_ctxt.ul_nas_count = 0; - tmp_ue_emm_ctx.security_ctxt.dl_nas_count = 0; - tmp_ue_emm_ctx.procedure_transaction_id = pdn_con_req.proc_transaction_id; + emm_ctx->security_ctxt.ul_nas_count = 0; + emm_ctx->security_ctxt.dl_nas_count = 0; + emm_ctx->procedure_transaction_id = pdn_con_req.proc_transaction_id; //Set ECM context - ue_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id; - ue_ecm_ctx.mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + ecm_ctx->imsi = 0; + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + ecm_ctx->mme_ue_s1ap_id = emm_ctx->mme_ue_s1ap_id; uint8_t eps_bearer_id = pdn_con_req.eps_bearer_id; //TODO: Unused //Save attach request type - tmp_ue_emm_ctx.attach_type = attach_req.eps_attach_type; + emm_ctx->attach_type = attach_req.eps_attach_type; //Save whether ESM information transfer is necessary - ue_ecm_ctx.eit = pdn_con_req.esm_info_transfer_flag_present; + ecm_ctx->eit = pdn_con_req.esm_info_transfer_flag_present; //m_s1ap_log->console("EPS Bearer id: %d\n", eps_bearer_id); - //Add eNB info to UE ctxt - memcpy(&ue_ecm_ctx.enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + //Add eNB info to UE ctxt + memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); //Initialize E-RABs for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) { - ue_ecm_ctx.erabs_ctx[i].state = ERAB_DEACTIVATED; - ue_ecm_ctx.erabs_ctx[i].erab_id = i; + ecm_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; + ecm_ctx->erabs_ctx[i].erab_id = i; } - m_s1ap_log->console("Attach request -- IMSI: %015lu\n", ue_ecm_ctx.imsi); - m_s1ap_log->info("Attach request -- IMSI: %015lu\n", ue_ecm_ctx.imsi); - m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ue_ecm_ctx.enb_ue_s1ap_id, ue_ecm_ctx.mme_ue_s1ap_id); + m_s1ap_log->console("Attach request -- IMSI: %015lu\n", ecm_ctx->imsi); + m_s1ap_log->info("Attach request -- IMSI: %015lu\n", ecm_ctx->imsi); + m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); m_s1ap_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]); @@ -535,12 +544,12 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, m_s1ap_log->info("Could not find M-TMSI=0x%x. Sending Id Request\n", m_tmsi); //m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); - //We do not know the IMSI of the UE yet - //This will be removed when the identity response is received - tmp_ue_emm_ctx.mme_ue_s1ap_id = ue_ecm_ctx.mme_ue_s1ap_id; - m_s1ap->store_tmp_ue_emm_ctx(tmp_ue_emm_ctx); + //Store temporary ue context + ue_ctx_t *new_ctx = new ue_ctx_t; + memcpy(new_ctx,&ue_ctx,sizeof(ue_ctx_t)); + m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(new_ctx); - pack_identity_request(reply_buffer, ue_ecm_ctx.enb_ue_s1ap_id, ue_ecm_ctx.mme_ue_s1ap_id); + pack_identity_request(reply_buffer, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); *reply_flag = true; return true; } From 1f3ccb9bda2d44252c2cfdd1f3a05f93e186b23e Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 14 Mar 2018 18:07:07 +0000 Subject: [PATCH 081/143] Fixed bug in integrity check, UE is IMSI attaching again. --- srsepc/hdr/mme/s1ap.h | 4 ++-- srsepc/src/mme/s1ap.cc | 8 ++++++-- srsepc/src/mme/s1ap_nas_transport.cc | 13 +++---------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index b2c741d26..d417d9442 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -80,8 +80,8 @@ public: enb_ctx_t* find_enb_ctx(uint16_t enb_id); void add_new_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo* enb_sri); - bool add_ue_ctx_to_imsi_map(const ue_ctx_t *ue_ctx); - bool add_ue_ctx_to_mme_ue_s1ap_id_map(const ue_ctx_t *ue_ctx); + bool add_ue_ctx_to_imsi_map(ue_ctx_t *ue_ctx); + bool add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx_t *ue_ctx); ue_ctx_t* find_ue_ctx_from_imsi(uint64_t imsi); ue_ctx_t* find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id); diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index a541f00e3..4aeb17011 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -384,7 +384,7 @@ s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) } */ bool -s1ap::add_ue_ctx_to_imsi_map(const ue_ctx_t *ue_ctx) +s1ap::add_ue_ctx_to_imsi_map(ue_ctx_t *ue_ctx) { std::map::iterator ctx_it = m_imsi_to_ue_ctx.find(ue_ctx->emm_ctx.imsi); if(ctx_it != m_imsi_to_ue_ctx.end()) @@ -401,11 +401,13 @@ s1ap::add_ue_ctx_to_imsi_map(const ue_ctx_t *ue_ctx) return false; } } + m_imsi_to_ue_ctx.insert(std::pair(ue_ctx->emm_ctx.imsi, ue_ctx)); + m_s1ap_log->debug("Saved UE context corresponding to IMSI %015lu\n",ue_ctx->emm_ctx.imsi); return true; } bool -s1ap::add_ue_ctx_to_mme_ue_s1ap_id_map(const ue_ctx_t *ue_ctx) +s1ap::add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx_t *ue_ctx) { if(ue_ctx->ecm_ctx.mme_ue_s1ap_id == 0) { @@ -427,6 +429,8 @@ s1ap::add_ue_ctx_to_mme_ue_s1ap_id_map(const ue_ctx_t *ue_ctx) return false; } } + m_mme_ue_s1ap_id_to_ue_ctx.insert(std::pair(ue_ctx->ecm_ctx.mme_ue_s1ap_id, ue_ctx)); + m_s1ap_log->debug("Saved UE context corresponding to MME UE S1AP Id %d\n",ue_ctx->ecm_ctx.mme_ue_s1ap_id); return true; } diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 336d84143..135e99ae2 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -136,7 +136,6 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA uint8_t pd, msg_type, sec_hdr_type; uint32_t enb_ue_s1ap_id = ul_xport->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID; uint32_t mme_ue_s1ap_id = ul_xport->MME_UE_S1AP_ID.MME_UE_S1AP_ID; - ue_emm_ctx_t *ue_emm_ctx = NULL; bool mac_valid = false; //Get UE ECM context @@ -231,7 +230,7 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA { //Integrity protected NAS message, possibly chiphered. emm_ctx->security_ctxt.ul_nas_count++; - mac_valid = integrity_check(ue_emm_ctx,nas_msg); + mac_valid = integrity_check(emm_ctx,nas_msg); if(!mac_valid){ m_s1ap_log->warning("Invalid MAC in NAS message type 0x%x.\n", msg_type); m_pool->deallocate(nas_msg); @@ -273,14 +272,8 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA if(*reply_flag == true) { - if(ue_emm_ctx != NULL){ - m_s1ap_log->console("DL NAS: Sent Downlink NAs Message. DL NAS Count=%d, UL NAS count=%d\n",emm_ctx->security_ctxt.dl_nas_count,emm_ctx->security_ctxt.ul_nas_count ); - m_s1ap_log->info("DL NAS: Sent Downlink NAS message. DL NAS Count=%d, UL NAS count=%d\n",emm_ctx->security_ctxt.dl_nas_count, emm_ctx->security_ctxt.ul_nas_count); - } - else{ - m_s1ap_log->console("DL NAS: Sent Downlink NAS Message\n"); - m_s1ap_log->console("DL NAS: Sent Downlink NAS Message\n"); - } + m_s1ap_log->console("DL NAS: Sent Downlink NAs Message. DL NAS Count=%d, UL NAS count=%d\n",emm_ctx->security_ctxt.dl_nas_count,emm_ctx->security_ctxt.ul_nas_count ); + m_s1ap_log->info("DL NAS: Sent Downlink NAS message. DL NAS Count=%d, UL NAS count=%d\n",emm_ctx->security_ctxt.dl_nas_count, emm_ctx->security_ctxt.ul_nas_count); } m_pool->deallocate(nas_msg); return true; From a8bfa497efa133d97379de1f404677d6ebfa7f11 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 14 Mar 2018 18:34:27 +0000 Subject: [PATCH 082/143] Remove some commented out code. --- srsepc/src/mme/s1ap.cc | 186 ----------------------------------------- 1 file changed, 186 deletions(-) diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 4aeb17011..e0f5e1422 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -346,43 +346,6 @@ s1ap::delete_enb_ctx(int32_t assoc_id) //UE Context Management -/*void -s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) -{ - std::map::iterator ctx_it = m_imsi_to_ue_ctx.find(ue_ctx.emm_ctx.imsi); - if(ctx_it != m_imsi_to_ue_ctx.end()) - { - m_s1ap_log->warning("UE Context already exists. Replacing UE Context\n"); - delete ctx_it->second; - m_imsi_to_ue_ctx.erase(ctx_it); - } - std::map::iterator imsi_it = m_mme_ue_s1ap_id_to_imsi.find(ue_ctx.ecm_ctx.mme_ue_s1ap_id); - if(imsi_it != m_mme_ue_s1ap_id_to_imsi.end()) - { - m_s1ap_log->warning("MME UE S1AP Id already exists, replacing it.\n"); - m_mme_ue_s1ap_id_to_imsi.erase(imsi_it); - } - - ue_ctx_t *new_ctx = new ue_ctx_t; - memcpy(new_ctx, &ue_ctx,sizeof(ue_ctx)); - - //This map will store UEs context - m_imsi_to_ue_ctx.insert(std::pair(new_ctx->emm_ctx.imsi,new_ctx)); - m_mme_ue_s1ap_id_to_imsi.insert(std::pair(ue_ctx.ecm_ctx.mme_ue_s1ap_id,ue_ctx.emm_ctx.imsi)); - - //Store which enb currently holds the UE - std::map::iterator it_enb = m_sctp_to_enb_id.find(new_ctx->ecm_ctx.enb_sri.sinfo_assoc_id); - uint16_t enb_id = it_enb->second; - std::map >::iterator it_ue_id = m_enb_id_to_ue_ids.find(enb_id); - if(it_ue_id==m_enb_id_to_ue_ids.end()) - { - m_s1ap_log->error("Could not find eNB's UEs\n"); - return; - } - it_ue_id->second.insert(new_ctx->ecm_ctx.mme_ue_s1ap_id); - return; -} -*/ bool s1ap::add_ue_ctx_to_imsi_map(ue_ctx_t *ue_ctx) { @@ -434,33 +397,6 @@ s1ap::add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx_t *ue_ctx) return true; } - /* -void -s1ap::store_tmp_ue_emm_ctx(const ue_emm_ctx_t &tmp_ue_emm_ctx) -{ - ue_emm_ctx_t *ue_ptr = new ue_emm_ctx_t; - memcpy(ue_ptr,&tmp_ue_emm_ctx,sizeof(tmp_ue_emm_ctx)); - - //This map will store UE's ECM context. - m_mme_ue_s1ap_id_to_tmp_ue_emm_ctx.insert(std::pair(ue_ptr->mme_ue_s1ap_id,ue_ptr)); -} - -bool -s1ap::get_tmp_ue_emm_ctx(uint32_t mme_ue_s1ap_id, ue_emm_ctx_t* ue_emm_ptr) -{ - - std::map::iterator it = m_mme_ue_s1ap_id_to_tmp_ue_emm_ctx.find(mme_ue_s1ap_id); - if(it == m_mme_ue_s1ap_id_to_tmp_ue_emm_ctx.end() ) - { - return false; - } - memcpy(ue_emm_ptr, it->second,sizeof(ue_emm_ctx_t)); - delete it->second; - m_mme_ue_s1ap_id_to_tmp_ue_emm_ctx.erase(it); - return true; -} - */ - ue_ctx_t* s1ap::find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) { @@ -647,125 +583,3 @@ s1ap::print_enb_ctx_info(const std::string &prefix, const enb_ctx_t &enb_ctx) } //namespace srsepc - /* -void -s1ap::add_new_ue_emm_ctx(const ue_emm_ctx_t &ue_emm_ctx) -{ - std::map::iterator emm_ctx_it = m_imsi_to_ue_emm_ctx.find(ue_emm_ctx.imsi); - if(emm_ctx_it != m_imsi_to_ue_emm_ctx.end()) - { - m_s1ap_log->warning("EMM Context already exists. Replacing EMM Context\n"); - delete emm_ctx_it->second; - m_imsi_to_ue_emm_ctx.erase(emm_ctx_it); - } - - ue_emm_ctx_t *ue_ptr = new ue_emm_ctx_t; - memcpy(ue_ptr,&ue_emm_ctx,sizeof(ue_emm_ctx)); - //This map will store UEs EMM context - m_imsi_to_ue_emm_ctx.insert(std::pair(ue_ptr->imsi,ue_ptr)); -} - */ - -/* - void - s1ap::add_new_ue_ecm_ctx(const ue_ecm_ctx_t &ue_ecm_ctx) - { - ue_ecm_ctx_t *ue_ptr = new ue_ecm_ctx_t; - memcpy(ue_ptr,&ue_ecm_ctx,sizeof(ue_ecm_ctx)); - - //This map will store UE's ECM context. - m_mme_ue_s1ap_id_to_ue_ecm_ctx.insert(std::pair(ue_ptr->mme_ue_s1ap_id,ue_ptr)); - //Store which enb currently holds the UE - std::map::iterator it_enb = m_sctp_to_enb_id.find(ue_ptr->enb_sri.sinfo_assoc_id); - uint16_t enb_id = it_enb->second; - std::map >::iterator it_ue_id = m_enb_id_to_ue_ids.find(enb_id); - if(it_ue_id==m_enb_id_to_ue_ids.end()) - { - m_s1ap_log->error("Could not find eNB's UEs\n"); - return; - } - it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); - } - */ - /* -ue_emm_ctx_t* -s1ap::find_ue_emm_ctx_from_imsi(uint64_t imsi) -{ - std::map::iterator it = m_imsi_to_ue_emm_ctx.find(imsi); - if(it == m_imsi_to_ue_emm_ctx.end()) - { - return NULL; - } - else - { - return it->second; - } -} - -ue_ecm_ctx_t* -s1ap::find_ue_ecm_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) -{ - std::map::iterator it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_ue_s1ap_id); - if(it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) - { - return NULL; - } - else - { - return it->second; - } -}*/ - /* -bool -s1ap::delete_ue_emm_ctx(uint64_t imsi) -{ - std::map::iterator ue_emm_ctx_it = m_imsi_to_ue_emm_ctx.find(imsi); - if(ue_emm_ctx_it == m_imsi_to_ue_emm_ctx.end()) - { - m_s1ap_log->info("Cannot delete UE EMM context, UE not found. IMSI: %d\n", imsi); - return false; - } - - //Delete UE context - m_imsi_to_ue_emm_ctx.erase(ue_emm_ctx_it); - delete ue_emm_ctx_it->second; - m_s1ap_log->info("Deleted UE EMM Context.\n"); - return true; -} - */ - /* -bool -s1ap::delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id) -{ - std::map::iterator ue_ecm_ctx_it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_ue_s1ap_id); - if(ue_ecm_ctx_it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) - { - m_s1ap_log->info("Cannot delete UE ECM context, UE not found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); - return false; - } - ue_ecm_ctx_t* ue_ecm_ctx = ue_ecm_ctx_it->second; - - //Delete UE within eNB UE set - std::map::iterator it = m_sctp_to_enb_id.find(ue_ecm_ctx->enb_sri.sinfo_assoc_id); - if(it == m_sctp_to_enb_id.end() ) - { - m_s1ap_log->error("Could not find eNB for this request.\n"); - return false; - } - uint16_t enb_id = it->second; - std::map >::iterator ue_set = m_enb_id_to_ue_ids.find(enb_id); - if(ue_set == m_enb_id_to_ue_ids.end()) - { - m_s1ap_log->error("Could not find the eNB's UEs.\n"); - return false; - } - ue_set->second.erase(mme_ue_s1ap_id); - - //Delete UE context - m_mme_ue_s1ap_id_to_ue_ecm_ctx.erase(ue_ecm_ctx_it); - delete ue_ecm_ctx; - m_s1ap_log->info("Deleted UE ECM Context.\n"); - - return true; -} - */ From 0da56b6a5a25355c4de32a6328c5c71804f23094 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 15 Mar 2018 16:05:36 +0000 Subject: [PATCH 083/143] Fixed bug with in GUTI attach with unkown M-TMSI. --- srsepc/src/mme/mme_gtpc.cc | 2 +- srsepc/src/mme/s1ap_nas_transport.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 53277e89c..e1a172600 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -216,7 +216,7 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu) //Save create session response info to E-RAB context ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_imsi(imsi); if(ue_ctx == NULL){ - m_mme_gtpc_log->error("Could not find UE context\n"); + m_mme_gtpc_log->error("Could not find UE context. IMSI %015lu\n", imsi); return; } ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 135e99ae2..09affd296 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -950,8 +950,8 @@ s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ return false; } - //Store UE EMM context - //m_s1ap->add_new_ue_emm_ctx(ue_emm_ctx); + //Store UE context im IMSI map + m_s1ap->add_ue_ctx_to_imsi_map(ue_ctx); //Pack NAS Authentication Request in Downlink NAS Transport msg pack_authentication_request(reply_msg, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id, autn, rand); From d932a2ad8534d6a551d546795d5ca04af9533902 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 15 Mar 2018 20:04:50 +0000 Subject: [PATCH 084/143] Starting to add the ability to handle UE context release complete. --- srsepc/hdr/mme/s1ap_common.h | 1 + srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h | 1 + srsepc/src/mme/s1ap.cc | 3 ++ srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 57 +++++++++++++++++++++++++++ srsepc/src/mme/s1ap_nas_transport.cc | 21 +++++----- 5 files changed, 71 insertions(+), 12 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index adb9f68e0..9fea71d3f 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -140,6 +140,7 @@ typedef struct{ emm_state_t state; uint32_t mme_ue_s1ap_id; uint8_t attach_type; + struct in_addr ue_ip; srslte::gtpc_f_teid_ie sgw_ctrl_fteid; } ue_emm_ctx_t; diff --git a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h index 44458aea6..6fc599101 100644 --- a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h @@ -52,6 +52,7 @@ public: bool handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT *in_ctxt_resp); bool handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQUEST_STRUCT *ue_rel, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool send_ue_context_release_command(ue_ecm_ctx_t *ecm_ctx, srslte::byte_buffer_t *reply_buffer); + bool handle_ue_context_release_complete(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASECOMPLETE_STRUCT *rel_comp); private: s1ap_ctx_mngmt_proc(); diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index e0f5e1422..efbe60c0a 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -283,6 +283,9 @@ s1ap::handle_successful_outcome(LIBLTE_S1AP_SUCCESSFULOUTCOME_STRUCT *msg) case LIBLTE_S1AP_SUCCESSFULOUTCOME_CHOICE_INITIALCONTEXTSETUPRESPONSE: m_s1ap_log->info("Received Initial Context Setup Response.\n"); return m_s1ap_ctx_mngmt_proc->handle_initial_context_setup_response(&msg->choice.InitialContextSetupResponse); + case LIBLTE_S1AP_SUCCESSFULOUTCOME_CHOICE_UECONTEXTRELEASECOMPLETE: + m_s1ap_log->info("Received UE Context Release Complete\n"); + return m_s1ap_ctx_mngmt_proc->handle_ue_context_release_complete(&msg->choice.UEContextReleaseComplete); default: m_s1ap_log->error("Unhandled successful outcome message: %s\n", liblte_s1ap_successfuloutcome_choice_text[msg->choice_type]); } diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 3485b6e2f..6f575efe4 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -349,5 +349,62 @@ s1ap_ctx_mngmt_proc::send_ue_context_release_command(ue_ecm_ctx_t *ecm_ctx, srsl return true; } +bool +s1ap_ctx_mngmt_proc::handle_ue_context_release_complete(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASECOMPLETE_STRUCT *rel_comp) +{ + /* + typedef struct{ + bool ext; + LIBLTE_S1AP_MME_UE_S1AP_ID_STRUCT MME_UE_S1AP_ID; + LIBLTE_S1AP_ENB_UE_S1AP_ID_STRUCT eNB_UE_S1AP_ID; + LIBLTE_S1AP_CRITICALITYDIAGNOSTICS_STRUCT CriticalityDiagnostics; + bool CriticalityDiagnostics_present; + LIBLTE_S1AP_USERLOCATIONINFORMATION_STRUCT UserLocationInformation; + bool UserLocationInformation_present; + }LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASECOMPLETE_STRUCT; + */ + + uint32_t mme_ue_s1ap_id = rel_comp->MME_UE_S1AP_ID.MME_UE_S1AP_ID; + m_s1ap_log->info("Received UE Context Release Complete. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + m_s1ap_log->console("Received UE Context Release Complete. MME-UE S1AP Id %d\n", mme_ue_s1ap_id); + + ue_ctx_t * ue_ctx = m_s1ap->find_ue_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); + if(ue_ctx == NULL) + { + m_s1ap_log->info("No UE context to release found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + m_s1ap_log->console("No UE context to release found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + return false; + } + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + + //Delete user plane context at the SPGW (but keep GTP-C connection). + if (ecm_ctx->state == ECM_STATE_CONNECTED) + { + //There are active E-RABs, send release access mearers request + m_s1ap_log->console("There are active E-RABs, send release access mearers request"); + m_s1ap_log->info("There are active E-RABs, send release access mearers request"); + m_mme_gtpc->send_release_access_bearers_request(ecm_ctx->imsi); + //The handle_releease_access_bearers_response function will make sure to mark E-RABS DEACTIVATED + //It will release the UEs downstream S1-u and keep the upstream S1-U connection active. + } + else + { + //No ECM Context to release + m_s1ap_log->info("UE is not ECM connected. No need to release S1-U. MME UE S1AP Id %d\n", mme_ue_s1ap_id); + m_s1ap_log->console("UE is not ECM connected. No need to release S1-U. MME UE S1AP Id %d\n", mme_ue_s1ap_id); + //Make sure E-RABS are merked as DEACTIVATED. + for(int i=0;ierabs_ctx[i].state = ERAB_DEACTIVATED; + } + } + + //Delete UE context + m_s1ap->release_ue_ecm_ctx(ue_ctx->ecm_ctx.mme_ue_s1ap_id); + m_s1ap_log->info("UE Context Release Completed.\n"); + m_s1ap_log->console("UE Context Release Completed.\n"); + return true; +} + } //namespace srsepc diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 09affd296..103d9f492 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -699,12 +699,14 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, //Save whether secure ESM information transfer is necessary ecm_ctx->eit = false; - //Initialize E-RABs - for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) + //Get UE IP, and uplink F-TEID + if(emm_ctx->ue_ip.s_addr == 0 ) { - ecm_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; - ecm_ctx->erabs_ctx[i].erab_id = i; + m_s1ap_log->error("UE has no valid IP assigned upon reception of service request"); } + + m_s1ap_log->console("UE previously assigned IP: %s",inet_ntoa(emm_ctx->ue_ip)); + //Mark E-RABs as setup, but not active yet //Re-generate K_eNB liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); @@ -932,16 +934,11 @@ s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ m_s1ap_log->info("Id Response -- IMSI: %015lu\n", imsi); m_s1ap_log->console("Id Response -- IMSI: %015lu\n", imsi); - ecm_ctx->imsi = imsi; - //Get UE EMM context - //if(m_s1ap->get_tmp_ue_emm_ctx(ue_ecm_ctx->mme_ue_s1ap_id, &ue_emm_ctx) == false) - //{ - // m_s1ap_log->error("Could not find UE's temporary EMM context. MME UE S1AP Id: %d\n",ue_ecm_ctx->mme_ue_s1ap_id); - // return false; - //} + //Set UE's context IMSI emm_ctx->imsi=imsi; - + ecm_ctx->imsi = imsi; + //Get Authentication Vectors from HSS if(!m_hss->gen_auth_info_answer(imsi, emm_ctx->security_ctxt.k_asme, autn, rand, emm_ctx->security_ctxt.xres)) { From 04d5676db027fbec32ef2d55b93c3e1b6339de6b Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 16 Mar 2018 12:55:58 +0000 Subject: [PATCH 085/143] Fixed bug to save UE ctx on the mme_ue_s1ap_id_map upon reception of the service request. Service request is now working again for the case where the UE is ECM-IDLE. --- srsepc/src/mme/mme_gtpc.cc | 3 +++ srsepc/src/mme/s1ap_nas_transport.cc | 3 +++ 2 files changed, 6 insertions(+) diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index e1a172600..c5698af95 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -222,6 +222,9 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu) ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + //Save UE IP to nas ctxt + emm_ctx->ue_ip.s_addr = cs_resp->paa.ipv4; + m_mme_gtpc_log->console("SPGW Allocated IP %s to ISMI %015lu",inet_ntoa(emm_ctx->ue_ip),emm_ctx->imsi); //Save SGW ctrl F-TEID in GTP-C context std::map::iterator it_g = m_imsi_to_gtpc_ctx.find(imsi); if(it_g == m_imsi_to_gtpc_ctx.end()) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 103d9f492..1eece94a4 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -712,6 +712,9 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); m_s1ap_log->console("UE Ctr TEID %d\n", emm_ctx->sgw_ctrl_fteid.teid); + + //Save UE ctx to MME UE S1AP id + m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx); m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx,&ecm_ctx->erabs_ctx[5]); } else From 0f45369d44cec4358d0851bb81fcaf52cbb9f5ed Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 16 Mar 2018 15:07:23 +0000 Subject: [PATCH 086/143] Trying to fix service request when ECM content is present. --- srsepc/src/mme/mme_gtpc.cc | 2 +- srsepc/src/mme/s1ap_nas_transport.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index c5698af95..a27e12a4d 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -224,7 +224,7 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu) //Save UE IP to nas ctxt emm_ctx->ue_ip.s_addr = cs_resp->paa.ipv4; - m_mme_gtpc_log->console("SPGW Allocated IP %s to ISMI %015lu",inet_ntoa(emm_ctx->ue_ip),emm_ctx->imsi); + m_mme_gtpc_log->console("SPGW Allocated IP %s to ISMI %015lu\n",inet_ntoa(emm_ctx->ue_ip),emm_ctx->imsi); //Save SGW ctrl F-TEID in GTP-C context std::map::iterator it_g = m_imsi_to_gtpc_ctx.find(imsi); if(it_g == m_imsi_to_gtpc_ctx.end()) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 1eece94a4..df31dfdc6 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -676,9 +676,9 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, //Delete eNB context and connect. m_s1ap_log->console("Service Request -- User has ECM context already\n"); m_s1ap_log->info("Service Request -- User has ECM context already\n"); - m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); + //m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); //int default_bearer_id = 5; - //m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[default_bearer_id]); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[5]); //FIXME Send Modify context request OR send ctx release command and wait for the reply. } else if(ecm_ctx->state == ECM_STATE_IDLE) From 50aeda200966a22ceb60fcfaf217c15757a95d3f Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 20 Mar 2018 14:52:34 +0000 Subject: [PATCH 087/143] Fixed bug in SPGW when replacing an existing eNB S1-U TEID. Service request seems to be working for the cases of ECM idle and ECM connected. --- srsepc/src/mme/s1ap_nas_transport.cc | 30 ++++++++++++++++------------ srsepc/src/spgw/spgw.cc | 4 +++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index df31dfdc6..ff95a7624 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -667,22 +667,26 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, { m_s1ap_log->error("Service Request -- User is ECM CONNECTED\n"); - //Service request to Connected UE. + //Release previous context + m_s1ap_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); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); + m_s1ap->release_ue_ecm_ctx(ecm_ctx->mme_ue_s1ap_id); + } + //Handle service request from Connected UE. //Set eNB UE S1ap identity - ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; - m_s1ap_log->console("Service Request -- eNB UE S1AP Id %d \n", enb_ue_s1ap_id); - m_s1ap_log->info("Service Request -- eNB UE S1AP Id %d\n ", enb_ue_s1ap_id); + // ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + // m_s1ap_log->console("Service Request -- eNB UE S1AP Id %d \n", enb_ue_s1ap_id); + //m_s1ap_log->info("Service Request -- eNB UE S1AP Id %d\n ", enb_ue_s1ap_id); //Delete eNB context and connect. - m_s1ap_log->console("Service Request -- User has ECM context already\n"); - m_s1ap_log->info("Service Request -- User has ECM context already\n"); + //m_s1ap_log->console("Service Request -- User has ECM context already\n"); + //m_s1ap_log->info("Service Request -- User has ECM context already\n"); //m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); //int default_bearer_id = 5; - m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[5]); - //FIXME Send Modify context request OR send ctx release command and wait for the reply. - } - else if(ecm_ctx->state == ECM_STATE_IDLE) - { + //m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[5]); + //} + //else if(ecm_ctx->state == ECM_STATE_IDLE) + //{ ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; //UE not connect. Connect normally. @@ -716,12 +720,12 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, //Save UE ctx to MME UE S1AP id m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx); m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx,&ecm_ctx->erabs_ctx[5]); - } + /*} else { m_s1ap_log->console("ECM context is un-initialized.\n"); m_s1ap_log->error("ECM context is un-initialized.\n"); - } + }*/ } else { diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index 0acb37041..28dada151 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -593,8 +593,10 @@ spgw::handle_modify_bearer_request(struct srslte::gtpc_pdu *mb_req_pdu, struct s m_spgw_log->info("eNB Rx User TEID 0x%x, eNB Rx User IP %s\n", tunnel_ctx->dw_user_fteid.teid, inet_ntoa(addr3)); //Setup IP to F-TEID map + //bool ret = false; pthread_mutex_lock(&m_mutex); - m_ip_to_teid.insert(std::pair(tunnel_ctx->ue_ipv4, tunnel_ctx->dw_user_fteid)); + m_ip_to_teid[tunnel_ctx->ue_ipv4]=tunnel_ctx->dw_user_fteid; + //ret = m_ip_to_teid.insert(std::pair(tunnel_ctx->ue_ipv4, tunnel_ctx->dw_user_fteid)); pthread_mutex_unlock(&m_mutex); //Setting up Modify bearer response PDU From acc4f925bc43870a75e55d0405c006f1970b039d Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 20 Mar 2018 16:35:01 +0000 Subject: [PATCH 088/143] getting rid of boost::mutex on MME GTPc entity --- srsepc/src/mme/mme_gtpc.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index a27e12a4d..e25ea05d1 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -33,7 +33,8 @@ namespace srsepc{ mme_gtpc* mme_gtpc::m_instance = NULL; -boost::mutex mme_gtpc_instance_mutex; +pthread_mutex_t mme_gtpc_instance_mutex = PTHREAD_MUTEX_INITIALIZER; + mme_gtpc::mme_gtpc() { @@ -46,21 +47,23 @@ mme_gtpc::~mme_gtpc() mme_gtpc* mme_gtpc::get_instance(void) { - boost::mutex::scoped_lock lock(mme_gtpc_instance_mutex); + pthread_mutex_lock(&mme_gtpc_instance_mutex); if(NULL == m_instance) { m_instance = new mme_gtpc(); } + pthread_mutex_unlock(&mme_gtpc_instance_mutex); return(m_instance); } void mme_gtpc::cleanup(void) { - boost::mutex::scoped_lock lock(mme_gtpc_instance_mutex); + pthread_mutex_lock(&mme_gtpc_instance_mutex); if(NULL != m_instance) { delete m_instance; m_instance = NULL; } + pthread_mutex_unlock(&mme_gtpc_instance_mutex); } From 2ab25f4c1b55a4a1b2217acf0b8420a1b22dec02 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 20 Mar 2018 16:35:35 +0000 Subject: [PATCH 089/143] Getting rid of debug prints. --- srsepc/src/spgw/spgw.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index 2ef6facc0..f54eef7df 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -340,7 +340,7 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg) dest_addr.s_addr = dest_ip; //m_spgw_log->console("IP version: %d\n", version); - m_spgw_log->console("Received packet to IP: %s\n", inet_ntoa(dest_addr)); + //m_spgw_log->console("Received packet to IP: %s\n", inet_ntoa(dest_addr)); pthread_mutex_lock(&m_mutex); gtp_fteid_it = m_ip_to_teid.find(dest_ip); @@ -353,7 +353,7 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg) if(ip_found == false) { - m_spgw_log->console("IP Packet is not for any UE\n"); + //m_spgw_log->console("IP Packet is not for any UE\n"); return; } struct sockaddr_in enb_addr; From 1dd87e51133af37c4072082baf8f86828605dc27 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 20 Mar 2018 16:53:11 +0000 Subject: [PATCH 090/143] Getting rid of boost::mutext on enb singleton class --- srsenb/src/enb.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/srsenb/src/enb.cc b/srsenb/src/enb.cc index e440081d0..564775e5e 100644 --- a/srsenb/src/enb.cc +++ b/srsenb/src/enb.cc @@ -32,26 +32,27 @@ namespace srsenb { enb* enb::instance = NULL; -boost::mutex enb_instance_mutex; - +pthread_mutex_t enb_instance_mutex = PTHREAD_MUTEX_INITIALIZER; enb* enb::get_instance(void) { - boost::mutex::scoped_lock lock(enb_instance_mutex); + pthread_mutex_lock(&enb_instance_mutex); if(NULL == instance) { - instance = new enb(); + instance = new enb(); } + pthread_mutex_unlock(&enb_instance_mutex); return(instance); } void enb::cleanup(void) { srslte_dft_exit(); srslte::byte_buffer_pool::cleanup(); - boost::mutex::scoped_lock lock(enb_instance_mutex); + pthread_mutex_lock(&enb_instance_mutex); if(NULL != instance) { delete instance; instance = NULL; } + pthread_mutex_unlock(&enb_instance_mutex); } enb::enb() : started(false) { From 2d9c10102714b4fbb1b5dbe46346712331f9257b Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Wed, 21 Mar 2018 11:42:37 +0100 Subject: [PATCH 091/143] Check all DRB config parameters --- srsenb/src/enb_cfg_parser.cc | 48 +++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/srsenb/src/enb_cfg_parser.cc b/srsenb/src/enb_cfg_parser.cc index 669d2586b..b63c46058 100644 --- a/srsenb/src/enb_cfg_parser.cc +++ b/srsenb/src/enb_cfg_parser.cc @@ -1072,7 +1072,9 @@ int field_qci::parse(libconfig::Setting &root) parser::field_enum_num sn_field_len ("sn_field_length", &rlc_cfg->sn_field_len, liblte_rrc_sn_field_length_num, LIBLTE_RRC_SN_FIELD_LENGTH_N_ITEMS); - sn_field_len.parse(q["rlc_config"]["ul_um"]); + if (sn_field_len.parse(q["rlc_config"]["ul_um"])) { + fprintf(stderr, "Error can't find sn_field_length in section ul_um\n"); + } } if (q["rlc_config"].exists("dl_um")) { @@ -1085,12 +1087,16 @@ int field_qci::parse(libconfig::Setting &root) parser::field_enum_num sn_field_len ("sn_field_length", &rlc_cfg->sn_field_len, liblte_rrc_sn_field_length_num, LIBLTE_RRC_SN_FIELD_LENGTH_N_ITEMS); - sn_field_len.parse(q["rlc_config"]["dl_um"]); + if (sn_field_len.parse(q["rlc_config"]["dl_um"])) { + fprintf(stderr, "Error can't find sn_field_length in section dl_um\n"); + } parser::field_enum_num t_reordering ("t_reordering", &rlc_cfg->t_reordering, liblte_rrc_t_reordering_num, LIBLTE_RRC_T_REORDERING_N_ITEMS); - t_reordering.parse(q["rlc_config"]["dl_um"]); + if (t_reordering.parse(q["rlc_config"]["dl_um"])) { + fprintf(stderr, "Error can't find t_reordering in section dl_um\n"); + } } // Parse RLC-AM section @@ -1100,22 +1106,30 @@ int field_qci::parse(libconfig::Setting &root) parser::field_enum_num t_poll_retx ("t_poll_retx", &rlc_cfg->t_poll_retx, liblte_rrc_t_poll_retransmit_num, LIBLTE_RRC_T_POLL_RETRANSMIT_N_ITEMS); - t_poll_retx.parse(q["rlc_config"]["ul_am"]); + if (t_poll_retx.parse(q["rlc_config"]["ul_am"])) { + fprintf(stderr, "Error can't find t_poll_retx in section ul_am\n"); + } parser::field_enum_num poll_pdu ("poll_pdu", &rlc_cfg->poll_pdu, liblte_rrc_poll_pdu_num, LIBLTE_RRC_POLL_PDU_N_ITEMS); - poll_pdu.parse(q["rlc_config"]["ul_am"]); + if (poll_pdu.parse(q["rlc_config"]["ul_am"])) { + fprintf(stderr, "Error can't find poll_pdu in section ul_am\n"); + } parser::field_enum_num poll_byte ("poll_byte", &rlc_cfg->poll_byte, liblte_rrc_poll_byte_num, LIBLTE_RRC_POLL_BYTE_N_ITEMS); - poll_byte.parse(q["rlc_config"]["ul_am"]); + if (poll_byte.parse(q["rlc_config"]["ul_am"])) { + fprintf(stderr, "Error can't find poll_byte in section ul_am\n"); + } parser::field_enum_num max_retx_thresh ("max_retx_thresh", &rlc_cfg->max_retx_thresh, liblte_rrc_max_retx_threshold_num, LIBLTE_RRC_MAX_RETX_THRESHOLD_N_ITEMS); - max_retx_thresh.parse(q["rlc_config"]["ul_am"]); + if (max_retx_thresh.parse(q["rlc_config"]["ul_am"])) { + fprintf(stderr, "Error can't find max_retx_thresh in section ul_am\n"); + } } if (q["rlc_config"].exists("dl_am")) { @@ -1124,12 +1138,16 @@ int field_qci::parse(libconfig::Setting &root) parser::field_enum_num t_reordering ("t_reordering", &rlc_cfg->t_reordering, liblte_rrc_t_reordering_num, LIBLTE_RRC_T_REORDERING_N_ITEMS); - t_reordering.parse(q["rlc_config"]["dl_am"]); + if (t_reordering.parse(q["rlc_config"]["dl_am"])) { + fprintf(stderr, "Error can't find t_reordering in section dl_am\n"); + } parser::field_enum_num t_status_prohibit ("t_status_prohibit", &rlc_cfg->t_status_prohibit, liblte_rrc_t_status_prohibit_num, LIBLTE_RRC_T_STATUS_PROHIBIT_N_ITEMS); - t_status_prohibit.parse(q["rlc_config"]["dl_am"]); + if (t_status_prohibit.parse(q["rlc_config"]["dl_am"])) { + fprintf(stderr, "Error can't find t_status_prohibit in section dl_am\n"); + } } @@ -1141,17 +1159,23 @@ int field_qci::parse(libconfig::Setting &root) LIBLTE_RRC_UL_SPECIFIC_PARAMETERS_STRUCT *lc_cfg = &cfg[qci].lc_cfg; parser::field priority ("priority", &lc_cfg->priority); - priority.parse(q["logical_channel_config"]); + if (priority.parse(q["logical_channel_config"])) { + fprintf(stderr, "Error can't find logical_channel_config in section priority\n"); + } parser::field_enum_num prioritized_bit_rate ("prioritized_bit_rate", &lc_cfg->prioritized_bit_rate, liblte_rrc_prioritized_bit_rate_num, LIBLTE_RRC_PRIORITIZED_BIT_RATE_N_ITEMS); - prioritized_bit_rate.parse(q["logical_channel_config"]); + if (prioritized_bit_rate.parse(q["logical_channel_config"])) { + fprintf(stderr, "Error can't find prioritized_bit_rate in section logical_channel_config\n"); + } parser::field_enum_num bucket_size_duration ("bucket_size_duration", &lc_cfg->bucket_size_duration, liblte_rrc_bucket_size_duration_num, LIBLTE_RRC_BUCKET_SIZE_DURATION_N_ITEMS); - bucket_size_duration.parse(q["logical_channel_config"]); + if (bucket_size_duration.parse(q["logical_channel_config"])) { + fprintf(stderr, "Error can't find bucket_size_duration in section logical_channel_config\n"); + } parser::field log_chan_group ("log_chan_group", &lc_cfg->log_chan_group); if (log_chan_group.parse(q["logical_channel_config"])) { From f4243656c913369b6d9acdcae0653862103c1626 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Wed, 21 Mar 2018 11:47:30 +0100 Subject: [PATCH 092/143] Check integrity_generate msg_size parameter --- srsue/src/upper/nas.cc | 90 +++++++++++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 27 deletions(-) diff --git a/srsue/src/upper/nas.cc b/srsue/src/upper/nas.cc index 763515ea4..7069f4a23 100644 --- a/srsue/src/upper/nas.cc +++ b/srsue/src/upper/nas.cc @@ -345,30 +345,38 @@ void nas::integrity_generate(uint8_t *key_128, bool nas::integrity_check(byte_buffer_t *pdu) { - uint8_t exp_mac[4]; - uint8_t *mac = &pdu->msg[1]; - int i; + if (!pdu) { + nas_log->error("Invalid PDU\n"); + return NULL; + } + if (pdu->N_bytes > 5) { + uint8_t exp_mac[4]; + uint8_t *mac = &pdu->msg[1]; + int i; - integrity_generate(&k_nas_int[16], - ctxt.rx_count, - SECURITY_DIRECTION_DOWNLINK, - &pdu->msg[5], - pdu->N_bytes-5, - &exp_mac[0]); - - // Check if expected mac equals the sent mac - for(i=0; i<4; i++){ - if(exp_mac[i] != mac[i]){ - nas_log->warning("Integrity check failure. Local: count=%d, [%02x %02x %02x %02x], " - "Received: count=%d, [%02x %02x %02x %02x]\n", - ctxt.rx_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; + integrity_generate(&k_nas_int[16], + ctxt.rx_count, + SECURITY_DIRECTION_DOWNLINK, + &pdu->msg[5], + pdu->N_bytes-5, + &exp_mac[0]); + + // Check if expected mac equals the sent mac + for(i=0; i<4; i++){ + if(exp_mac[i] != mac[i]){ + nas_log->warning("Integrity check failure. Local: count=%d, [%02x %02x %02x %02x], " + "Received: count=%d, [%02x %02x %02x %02x]\n", + ctxt.rx_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; + } } + nas_log->info("Integrity check ok. Local: count=%d, Received: count=%d\n", + ctxt.rx_count, pdu->msg[5]); + return true; + } else { + nas_log->error("Invalid integrity check PDU size (%d)\n", pdu->N_bytes); } - nas_log->info("Integrity check ok. Local: count=%d, Received: count=%d\n", - ctxt.rx_count, pdu->msg[5]); - return true; } void nas::cipher_encrypt(byte_buffer_t *pdu) @@ -454,6 +462,17 @@ bool nas::check_cap_replay(LIBLTE_MME_UE_SECURITY_CAPABILITIES_STRUCT *caps) ******************************************************************************/ void nas::parse_attach_accept(uint32_t lcid, byte_buffer_t *pdu) { + + if (!pdu) { + nas_log->error("Invalid PDU\n"); + return; + } + + if (pdu->N_bytes <= 5) { + nas_log->error("Invalid attach accept PDU size (%d)\n", pdu->N_bytes); + return; + } + LIBLTE_MME_ATTACH_ACCEPT_MSG_STRUCT attach_accept; LIBLTE_MME_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT act_def_eps_bearer_context_req; LIBLTE_MME_ATTACH_COMPLETE_MSG_STRUCT attach_complete; @@ -679,6 +698,17 @@ void nas::parse_identity_request(uint32_t lcid, byte_buffer_t *pdu) { void nas::parse_security_mode_command(uint32_t lcid, byte_buffer_t *pdu) { + + if (!pdu) { + nas_log->error("Invalid PDU\n"); + return; + } + + if (pdu->N_bytes <= 5) { + nas_log->error("Invalid security mode command PDU size (%d)\n", pdu->N_bytes); + return; + } + LIBLTE_MME_SECURITY_MODE_COMMAND_MSG_STRUCT sec_mode_cmd; LIBLTE_MME_SECURITY_MODE_COMPLETE_MSG_STRUCT sec_mode_comp; @@ -808,6 +838,8 @@ void nas::parse_emm_information(uint32_t lcid, byte_buffer_t *pdu) { ******************************************************************************/ void nas::send_attach_request() { + + LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT attach_req; byte_buffer_t *msg = pool_allocate; if (!msg) { @@ -861,12 +893,16 @@ void nas::send_attach_request() { (LIBLTE_BYTE_MSG_STRUCT *) msg); // Add MAC - integrity_generate(&k_nas_int[16], - ctxt.tx_count, - SECURITY_DIRECTION_UPLINK, - &msg->msg[5], - msg->N_bytes - 5, - &msg->msg[1]); + if (msg->N_bytes > 5) { + integrity_generate(&k_nas_int[16], + ctxt.tx_count, + SECURITY_DIRECTION_UPLINK, + &msg->msg[5], + msg->N_bytes - 5, + &msg->msg[1]); + } else { + nas_log->error("Invalid PDU size %d\n", msg->N_bytes); + } } else { attach_req.eps_mobile_id.type_of_id = LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMSI; usim->get_imsi_vec(attach_req.eps_mobile_id.imsi, 15); From 45cae1d1aba068fe4a9f3a3dc424fee6b51dc47d Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Wed, 21 Mar 2018 13:10:13 +0100 Subject: [PATCH 093/143] Fix srsENB DL TCP stalling --- srsenb/src/mac/scheduler.cc | 27 +++++++++++++++++---------- srsenb/src/mac/scheduler_metric.cc | 4 +--- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/srsenb/src/mac/scheduler.cc b/srsenb/src/mac/scheduler.cc index 51f161d4a..995363045 100644 --- a/srsenb/src/mac/scheduler.cc +++ b/srsenb/src/mac/scheduler.cc @@ -254,18 +254,22 @@ uint32_t sched::get_ul_buffer(uint16_t rnti) return ret; } +/* \Warning: This function is not mutexed because it can produce late changes on the buffer state while + * the scheduler is already allocating data, resulting in empty grants. + * Ideally we would like the scheduler to query the RLC for buffer states in order to get the most updated + * buffer state with the minimum overhead. However, the current architecture is designed to be compliant + * with the FAPI interface + */ int sched::dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue) { - pthread_mutex_lock(&mutex); - int ret = 0; - if (ue_db.count(rnti)) { + int ret = 0; + if (ue_db.count(rnti)) { ue_db[rnti].dl_buffer_state(lc_id, tx_queue, retx_queue); } else { Error("User rnti=0x%x not found\n", rnti); ret = -1; } - pthread_mutex_unlock(&mutex); - return ret; + return ret; } int sched::dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code) @@ -676,10 +680,11 @@ int sched::dl_sched_data(dl_sched_data_t data[MAX_DATA_LIST]) int nof_data_elems = 0; for(std::map::iterator iter=ue_db.begin(); iter!=ue_db.end(); ++iter) { - sched_ue *user = (sched_ue*) &iter->second; - uint16_t rnti = (uint16_t) iter->first; + sched_ue *user = (sched_ue*) &iter->second; + uint16_t rnti = (uint16_t) iter->first; - dl_harq_proc *h = dl_metric->get_user_allocation(user); + uint32_t data_before = user->get_pending_dl_new_data(current_tti); + dl_harq_proc *h = dl_metric->get_user_allocation(user); srslte_dci_format_t dci_format = user->get_dci_format(); data[nof_data_elems].dci_format = dci_format; @@ -706,10 +711,12 @@ int sched::dl_sched_data(dl_sched_data_t data[MAX_DATA_LIST]) Error("DCI format (%d) not implemented\n", dci_format); } if (tbs > 0) { - log_h->info("SCHED: DL %s rnti=0x%x, pid=%d, mask=0x%x, dci=%d,%d, n_rtx=%d, tbs=%d, buffer=%d, tb_en={%s,%s}\n", + log_h->info("SCHED: DL %s rnti=0x%x, pid=%d, mask=0x%x, dci=%d,%d, n_rtx=%d, tbs=%d, buffer=%d/%d, tb_en={%s,%s}\n", !is_newtx?"retx":"tx", rnti, h->get_id(), h->get_rbgmask(), data[nof_data_elems].dci_location.L, data[nof_data_elems].dci_location.ncce, h->nof_retx(0) + h->nof_retx(1), - tbs, user->get_pending_dl_new_data(current_tti), data[nof_data_elems].dci.tb_en[0]?"y":"n", + tbs, + data_before, user->get_pending_dl_new_data(current_tti), + data[nof_data_elems].dci.tb_en[0]?"y":"n", data[nof_data_elems].dci.tb_en[1]?"y":"n"); nof_data_elems++; } else { diff --git a/srsenb/src/mac/scheduler_metric.cc b/srsenb/src/mac/scheduler_metric.cc index f6fb9d9df..1d9cdb954 100644 --- a/srsenb/src/mac/scheduler_metric.cc +++ b/srsenb/src/mac/scheduler_metric.cc @@ -148,9 +148,7 @@ dl_harq_proc* dl_metric_rr::get_user_allocation(sched_ue *user) if (pending_data || (h && !h->is_empty())) { #endif if (nof_users_with_data) { - if (nof_users_with_data == 2) { - } - if ((current_tti%nof_users_with_data) != user->ue_idx) { + if ((current_tti%nof_users_with_data) != user->ue_idx) { return NULL; } } From 51e7b3fec69aa0c18b0ae59a7cc9cd77b5e82376 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 21 Mar 2018 12:14:11 +0000 Subject: [PATCH 094/143] Fixed IMSI print. --- srsepc/src/spgw/spgw.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index f54eef7df..e35a99be3 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -515,7 +515,7 @@ spgw::handle_create_session_request(struct srslte::gtpc_create_session_request * bool gtpc_present = m_imsi_to_ctr_teid.count(cs_req->imsi); if(gtpc_present) { - m_spgw_log->console("SPGW: GTP-C context for IMSI %015ul already exists.\n", cs_req->imsi); + m_spgw_log->console("SPGW: GTP-C context for IMSI %015lu already exists.\n", cs_req->imsi); delete_gtp_ctx(m_imsi_to_ctr_teid[cs_req->imsi]); m_spgw_log->console("SPGW: Deleted previous context.\n"); } From fa4d14652de0482b94b08df1f16a5a03899a124c Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Wed, 21 Mar 2018 13:32:19 +0100 Subject: [PATCH 095/143] Added mutex for ue_rem/buffer access for more safety --- srsenb/hdr/mac/scheduler.h | 6 +++--- srsenb/src/mac/scheduler.cc | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/srsenb/hdr/mac/scheduler.h b/srsenb/hdr/mac/scheduler.h index c3ca7d624..12c336c36 100644 --- a/srsenb/hdr/mac/scheduler.h +++ b/srsenb/hdr/mac/scheduler.h @@ -100,8 +100,8 @@ public: uint32_t get_ul_buffer(uint16_t rnti); uint32_t get_dl_buffer(uint16_t rnti); - int dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue); - int dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code); + int dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue); + int dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code); int dl_ant_info(uint16_t rnti, LIBLTE_RRC_ANTENNA_INFO_DEDICATED_STRUCT *dedicated); int dl_ack_info(uint32_t tti, uint16_t rnti, uint32_t tb_idx, bool ack); @@ -217,7 +217,7 @@ private: bool configured; - pthread_mutex_t mutex; + pthread_mutex_t mutex, mutex2; }; diff --git a/srsenb/src/mac/scheduler.cc b/srsenb/src/mac/scheduler.cc index 995363045..2e0504193 100644 --- a/srsenb/src/mac/scheduler.cc +++ b/srsenb/src/mac/scheduler.cc @@ -64,6 +64,7 @@ sched::sched() : bc_aggr_level(0), rar_aggr_level(0), avail_rbg(0), P(0), start_ } pthread_mutex_init(&mutex, NULL); + pthread_mutex_init(&mutex2, NULL); reset(); } @@ -71,6 +72,7 @@ sched::~sched() { srslte_regs_free(®s); pthread_mutex_destroy(&mutex); + pthread_mutex_destroy(&mutex2); } void sched::init(rrc_interface_mac *rrc_, srslte::log* log) @@ -173,13 +175,15 @@ int sched::ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t *ue_cfg) int sched::ue_rem(uint16_t rnti) { pthread_mutex_lock(&mutex); - int ret = 0; + pthread_mutex_lock(&mutex2); + int ret = 0; if (ue_db.count(rnti)) { ue_db.erase(rnti); } else { Error("User rnti=0x%x not found\n", rnti); ret = -1; } + pthread_mutex_unlock(&mutex2); pthread_mutex_unlock(&mutex); return ret; } @@ -217,13 +221,15 @@ int sched::bearer_ue_cfg(uint16_t rnti, uint32_t lc_id, sched_interface::ue_bear int sched::bearer_ue_rem(uint16_t rnti, uint32_t lc_id) { pthread_mutex_lock(&mutex); - int ret = 0; + pthread_mutex_lock(&mutex2); + int ret = 0; if (ue_db.count(rnti)) { ue_db[rnti].rem_bearer(lc_id); } else { Error("User rnti=0x%x not found\n", rnti); ret = -1; } + pthread_mutex_unlock(&mutex2); pthread_mutex_unlock(&mutex); return ret; } @@ -259,9 +265,13 @@ uint32_t sched::get_ul_buffer(uint16_t rnti) * Ideally we would like the scheduler to query the RLC for buffer states in order to get the most updated * buffer state with the minimum overhead. However, the current architecture is designed to be compliant * with the FAPI interface + * + * We add a new mutex used only in ue_rem to avoid the UE being removed in between the access to + * ue_db.count() and the access to the std::map. */ int sched::dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue) { + pthread_mutex_lock(&mutex2); int ret = 0; if (ue_db.count(rnti)) { ue_db[rnti].dl_buffer_state(lc_id, tx_queue, retx_queue); @@ -269,21 +279,23 @@ int sched::dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, Error("User rnti=0x%x not found\n", rnti); ret = -1; } + pthread_mutex_unlock(&mutex2); return ret; } +/* \Warning Read comment in dl_rlc_buffer_state() */ int sched::dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code) { - pthread_mutex_lock(&mutex); - int ret = 0; + pthread_mutex_lock(&mutex2); + int ret = 0; if (ue_db.count(rnti)) { ue_db[rnti].mac_buffer_state(ce_code); } else { Error("User rnti=0x%x not found\n", rnti); ret = -1; } - pthread_mutex_unlock(&mutex); - return ret; + pthread_mutex_unlock(&mutex2); + return ret; } int sched::dl_ant_info(uint16_t rnti, LIBLTE_RRC_ANTENNA_INFO_DEDICATED_STRUCT *dl_ant_info) { From 62dc65556a969ff46d5027ff61b9f006a7984ab4 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 21 Mar 2018 18:45:23 +0000 Subject: [PATCH 096/143] Fixed GUTI attach procedure when authentication is successful. Ping works again. --- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 8 +++++--- srsepc/src/mme/s1ap_nas_transport.cc | 27 ++++++++++++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 5f258ba8d..6d8da0129 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -179,7 +179,7 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, } //Send Reply to eNB - ssize_t n_sent = sctp_send(s1mme,reply_buffer->msg, reply_buffer->N_bytes, &ecm_ctx->enb_sri, 0); + ssize_t n_sent = sctp_send(s1mme,reply_buffer->msg, reply_buffer->N_bytes, &ecm_ctx->enb_sri, 0); if(n_sent == -1) { m_s1ap_log->error("Failed to send Initial Context Setup Request\n"); @@ -195,8 +195,10 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx, addr.s_addr = htonl(sgw_s1u_ip); m_s1ap_log->info("Sent Intial 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("Sent Intial Context Setup Request, E-RAB id %d\n",erab_ctx_req->e_RAB_ID.E_RAB_ID); - m_s1ap_log->console("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); + 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)); m_pool->deallocate(reply_buffer); m_pool->deallocate(nas_buffer); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 0846a0c4b..9c9180e86 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -274,8 +274,10 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA if(*reply_flag == true) { - m_s1ap_log->console("DL NAS: Sent Downlink NAs Message. DL NAS Count=%d, UL NAS count=%d\n",emm_ctx->security_ctxt.dl_nas_count,emm_ctx->security_ctxt.ul_nas_count ); + m_s1ap_log->console("DL NAS: Sent Downlink NAS Message. DL NAS Count=%d, UL NAS count=%d\n",emm_ctx->security_ctxt.dl_nas_count,emm_ctx->security_ctxt.ul_nas_count ); m_s1ap_log->info("DL NAS: Sent Downlink NAS message. DL NAS Count=%d, UL NAS count=%d\n",emm_ctx->security_ctxt.dl_nas_count, emm_ctx->security_ctxt.ul_nas_count); + m_s1ap_log->info("DL NAS: MME UE S1AP id %d\n",ecm_ctx->mme_ue_s1ap_id); + m_s1ap_log->console("DL NAS: MME UE S1AP id %d\n",ecm_ctx->mme_ue_s1ap_id); } m_pool->deallocate(nas_msg); return true; @@ -473,8 +475,8 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, if(it == m_s1ap->m_tmsi_to_imsi.end()) { - m_s1ap_log->console("Attach Request -- Could not find M-TMSI 0x%x", m_tmsi); - m_s1ap_log->info("Attach Request -- Could not find M-TMSI 0x%x", m_tmsi); + m_s1ap_log->console("Attach Request -- Could not find M-TMSI 0x%x\n", m_tmsi); + m_s1ap_log->info("Attach Request -- Could not find M-TMSI 0x%x\n", m_tmsi); //Could not find IMSI from M-TMSI, send Id request ue_ctx_t ue_ctx; @@ -558,8 +560,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, { ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; - m_s1ap_log->console("Found UE context. IMSI: %015lu\n",emm_ctx->imsi); - + m_s1ap_log->console("Found UE context. IMSI: %015lu, old MME UE S1AP Id %d\n",emm_ctx->imsi, ecm_ctx->mme_ue_s1ap_id); //Check NAS integrity bool msg_valid = false; emm_ctx->security_ctxt.ul_nas_count++; @@ -567,8 +568,15 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, if(msg_valid == true) { //Create new MME UE S1AP Identity - emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + uint32_t new_mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + //Make sure context from previous MME + if(ecm_ctx->mme_ue_s1ap_id!=0) + { + m_s1ap->release_ue_ecm_ctx(ecm_ctx->mme_ue_s1ap_id); + } + emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + ecm_ctx->mme_ue_s1ap_id = emm_ctx->mme_ue_s1ap_id; //Set EMM as de-registered emm_ctx->state = EMM_STATE_DEREGISTERED; //Save Attach type @@ -591,7 +599,8 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, ecm_ctx->erabs_ctx[i].erab_id = i; } - //m_s1ap->add_new_ue_ecm_ctx(ue_ecm_ctx); + //Store context based on MME UE S1AP id + m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx); //Create session request m_s1ap_log->console("GUTI Attach -- NAS Integrity OK."); m_mme_gtpc->send_create_session_request(emm_ctx->imsi); @@ -1158,8 +1167,8 @@ s1ap_nas_transport::integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t // Check if expected mac equals the sent mac for(i=0; i<4; i++){ if(exp_mac[i] != mac[i]){ - m_s1ap_log->warning("Integrity check failure. Local: count=%d, [%02x %02x %02x %02x], " - "Received: count=%d, [%02x %02x %02x %02x]\n", + m_s1ap_log->warning("Integrity check failure. UL Local: count=%d, [%02x %02x %02x %02x], " + "Received: UL count=%d, [%02x %02x %02x %02x]\n", emm_ctx->security_ctxt.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; From 3d3027f0b75017aea83ae000626142bbba131dc6 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 22 Mar 2018 14:12:48 +0000 Subject: [PATCH 097/143] Fixed GUTI attach when authentication fails. --- srsepc/src/mme/s1ap_nas_transport.cc | 56 ++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 9c9180e86..b37726e51 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -570,7 +570,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, //Create new MME UE S1AP Identity uint32_t new_mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); - //Make sure context from previous MME + //Make sure context from previous NAS connections is not present if(ecm_ctx->mme_ue_s1ap_id!=0) { m_s1ap->release_ue_ecm_ctx(ecm_ctx->mme_ue_s1ap_id); @@ -609,11 +609,61 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, } else { + emm_ctx->security_ctxt.ul_nas_count = 0; + emm_ctx->security_ctxt.dl_nas_count = 0; + + //Create new MME UE S1AP Identity + uint32_t new_mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + + //Make sure context from previous NAS connections is not present + if(ecm_ctx->mme_ue_s1ap_id!=0) + { + m_s1ap->release_ue_ecm_ctx(ecm_ctx->mme_ue_s1ap_id); + } + emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + ecm_ctx->mme_ue_s1ap_id = emm_ctx->mme_ue_s1ap_id; + //Set EMM as de-registered + emm_ctx->state = EMM_STATE_DEREGISTERED; + //Save Attach type + emm_ctx->attach_type = attach_req.eps_attach_type; + + //Set UE ECM context + ecm_ctx->imsi = ecm_ctx->imsi; + ecm_ctx->mme_ue_s1ap_id = ecm_ctx->mme_ue_s1ap_id; + + //Set eNB information + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + //Save whether secure ESM information transfer is necessary + ecm_ctx->eit = pdn_con_req.esm_info_transfer_flag_present; + + //Initialize E-RABs + for(uint i = 0 ; i< MAX_ERABS_PER_UE; i++) + { + ecm_ctx->erabs_ctx[i].state = ERAB_DEACTIVATED; + ecm_ctx->erabs_ctx[i].erab_id = i; + } + //Store context based on MME UE S1AP id + m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx); + //NAS integrity failed. Re-start authentication process. m_s1ap_log->console("GUTI Attach request NAS integrity failed.\n"); m_s1ap_log->console("RE-starting authentication procedure.\n"); - //pack_identity_request(); - //(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id) + uint8_t autn[16]; + uint8_t rand[16]; + //Get Authentication Vectors from HSS + if(!m_hss->gen_auth_info_answer(emm_ctx->imsi, emm_ctx->security_ctxt.k_asme, autn, rand, emm_ctx->security_ctxt.xres)) + { + m_s1ap_log->console("User not found. IMSI %015lu\n",emm_ctx->imsi); + m_s1ap_log->info("User not found. IMSI %015lu\n",emm_ctx->imsi); + return false; + } + pack_authentication_request(reply_buffer, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id, autn, rand); + + //Send reply to eNB + *reply_flag = true; + m_s1ap_log->info("Downlink NAS: Sent Authentication Request\n"); + m_s1ap_log->console("Downlink NAS: Sent Authentication Request\n"); return true; } } From 79517310d040e4303eb53923d00fc60e5bfe974e Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 22 Mar 2018 14:22:04 +0000 Subject: [PATCH 098/143] small fixes on identation --- srsepc/src/mme/s1ap_nas_transport.cc | 86 +++++++++++----------------- 1 file changed, 33 insertions(+), 53 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index b37726e51..19b1ff924 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -733,60 +733,40 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); m_s1ap->release_ue_ecm_ctx(ecm_ctx->mme_ue_s1ap_id); } - //Handle service request from Connected UE. - //Set eNB UE S1ap identity - // ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; - // m_s1ap_log->console("Service Request -- eNB UE S1AP Id %d \n", enb_ue_s1ap_id); - //m_s1ap_log->info("Service Request -- eNB UE S1AP Id %d\n ", enb_ue_s1ap_id); - - //Delete eNB context and connect. - //m_s1ap_log->console("Service Request -- User has ECM context already\n"); - //m_s1ap_log->info("Service Request -- User has ECM context already\n"); - //m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); - //int default_bearer_id = 5; - //m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx, &ecm_ctx->erabs_ctx[5]); - //} - //else if(ecm_ctx->state == ECM_STATE_IDLE) - //{ - ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; - - //UE not connect. Connect normally. - m_s1ap_log->console("Service Request -- User is ECM DISCONNECTED\n"); - m_s1ap_log->info("Service Request -- User is ECM DISCONNECTED\n"); - //Create ECM context - ecm_ctx->imsi = emm_ctx->imsi; - ecm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); - emm_ctx->mme_ue_s1ap_id = ecm_ctx->mme_ue_s1ap_id; - //Set eNB information - ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; - memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); - - //Save whether secure ESM information transfer is necessary - ecm_ctx->eit = false; - - //Get UE IP, and uplink F-TEID - if(emm_ctx->ue_ip.s_addr == 0 ) - { - m_s1ap_log->error("UE has no valid IP assigned upon reception of service request"); - } - - m_s1ap_log->console("UE previously assigned IP: %s",inet_ntoa(emm_ctx->ue_ip)); - //Mark E-RABs as setup, but not active yet - - //Re-generate K_eNB - liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); - m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); - m_s1ap_log->console("UE Ctr TEID %d\n", emm_ctx->sgw_ctrl_fteid.teid); - - //Save UE ctx to MME UE S1AP id - m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx); - m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx,&ecm_ctx->erabs_ctx[5]); - /*} - else + + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + + //UE not connect. Connect normally. + m_s1ap_log->console("Service Request -- User is ECM DISCONNECTED\n"); + m_s1ap_log->info("Service Request -- User is ECM DISCONNECTED\n"); + //Create ECM context + ecm_ctx->imsi = emm_ctx->imsi; + ecm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + emm_ctx->mme_ue_s1ap_id = ecm_ctx->mme_ue_s1ap_id; + //Set eNB information + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); + + //Save whether secure ESM information transfer is necessary + ecm_ctx->eit = false; + + //Get UE IP, and uplink F-TEID + if(emm_ctx->ue_ip.s_addr == 0 ) { - m_s1ap_log->console("ECM context is un-initialized.\n"); - m_s1ap_log->error("ECM context is un-initialized.\n"); - }*/ + m_s1ap_log->error("UE has no valid IP assigned upon reception of service request"); + } + + m_s1ap_log->console("UE previously assigned IP: %s",inet_ntoa(emm_ctx->ue_ip)); + //Mark E-RABs as setup, but not active yet + + //Re-generate K_eNB + liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); + m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); + m_s1ap_log->console("UE Ctr TEID %d\n", emm_ctx->sgw_ctrl_fteid.teid); + + //Save UE ctx to MME UE S1AP id + m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_initial_context_setup_request(emm_ctx, ecm_ctx,&ecm_ctx->erabs_ctx[5]); } else { From ba3a579a9211729adc51849ffe21d185d2a7e519 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 22 Mar 2018 17:04:40 +0000 Subject: [PATCH 099/143] Regenerating k_eNB on guti attach request. --- srsepc/src/mme/s1ap_nas_transport.cc | 86 ++++++---------------------- 1 file changed, 17 insertions(+), 69 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 19b1ff924..eb3fa85db 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -257,6 +257,10 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA m_s1ap_log->info("Uplink NAS: Authentication Failure\n"); handle_authentication_failure(nas_msg, ue_ctx, reply_buffer, reply_flag); break; + /* case LIBLTE_MME_MSG_TYPE_DETACH_REQUEST: + m_s1ap_log->info("Uplink NAS: Detach Request\n"); + handle_detach_request(nas_msg, ue_ctx, reply_buffer, reply_flag); + break;*/ default: m_s1ap_log->warning("Unhandled NAS integrity protected message 0x%x\n", msg_type ); m_s1ap_log->console("Unhandled NAS integrity protected message 0x%x\n", msg_type ); @@ -601,6 +605,11 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, //Store context based on MME UE S1AP id m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx); + + //Re-generate K_eNB + liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); + m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); + //Create session request m_s1ap_log->console("GUTI Attach -- NAS Integrity OK."); m_mme_gtpc->send_create_session_request(emm_ctx->imsi); @@ -972,14 +981,6 @@ s1ap_nas_transport::handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; - //Check if EMM context already exists - //ue_ctx_t *ue_tmp_ptr = m_s1ap->find_ue_ctx_from_imsi(imsi); - //if(ue_tmp_ptr != NULL) - //{ - // m_s1ap_log->warning("Unkonw GUTI, but UE's EMM context present.\n"); - // m_s1ap->delete_ue_emm_ctx(imsi); - //} - m_s1ap_log->info("Id Response -- IMSI: %015lu\n", imsi); m_s1ap_log->console("Id Response -- IMSI: %015lu\n", imsi); @@ -1036,25 +1037,9 @@ s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *n dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = ue_ctx->ecm_ctx.enb_ue_s1ap_id; dw_nas->HandoverRestrictionList_present=false; dw_nas->SubscriberProfileIDforRFP_present=false; - //m_s1ap_log->console("Tracking area accept to MME-UE S1AP Id %d\n", ue_ctx->mme_ue_s1ap_id); + //m_s1ap_log->console("Tracking area accept to MME-UE S1AP Id %d\n", ue_ctx->mme_ue_s1ap_id); LIBLTE_MME_TRACKING_AREA_UPDATE_ACCEPT_MSG_STRUCT tau_acc; - /* - bool t3412_present; - bool guti_present; - bool tai_list_present; - bool eps_bearer_context_status_present; - bool lai_present; - bool ms_id_present; - bool emm_cause_present; - bool t3402_present; - bool t3423_present; - bool equivalent_plmns_present; - bool emerg_num_list_present; - bool eps_network_feature_support_present; - bool additional_update_result_present; - bool t3412_ext_present; - */ //Get decimal MCC and MNC uint32_t mcc = 0; mcc += 0x000F & m_s1ap->m_s1ap_args.mcc; @@ -1105,46 +1090,6 @@ s1ap_nas_transport::handle_tracking_area_update_request(srslte::byte_buffer_t *n tau_acc.additional_update_result_present = false; tau_acc.t3412_ext_present = false; - - //eps_update_result = LIBLTE_MME_TR - /* -typedef struct{ - LIBLTE_MME_GPRS_TIMER_STRUCT t3412; - LIBLTE_MME_EPS_MOBILE_ID_STRUCT guti; - LIBLTE_MME_TRACKING_AREA_IDENTITY_LIST_STRUCT tai_list; - LIBLTE_MME_EPS_BEARER_CONTEXT_STATUS_STRUCT eps_bearer_context_status; - LIBLTE_MME_LOCATION_AREA_ID_STRUCT lai; - LIBLTE_MME_MOBILE_ID_STRUCT ms_id; - LIBLTE_MME_GPRS_TIMER_STRUCT t3402; - LIBLTE_MME_GPRS_TIMER_STRUCT t3423; - LIBLTE_MME_PLMN_LIST_STRUCT equivalent_plmns; - LIBLTE_MME_EMERGENCY_NUMBER_LIST_STRUCT emerg_num_list; - LIBLTE_MME_EPS_NETWORK_FEATURE_SUPPORT_STRUCT eps_network_feature_support; - LIBLTE_MME_GPRS_TIMER_3_STRUCT t3412_ext; - LIBLTE_MME_ADDITIONAL_UPDATE_RESULT_ENUM additional_update_result; - uint8 eps_update_result; - uint8 emm_cause; - bool t3412_present; - bool guti_present; - bool tai_list_present; - bool eps_bearer_context_status_present; - bool lai_present; - bool ms_id_present; - bool emm_cause_present; - bool t3402_present; - bool t3423_present; - bool equivalent_plmns_present; - bool emerg_num_list_present; - bool eps_network_feature_support_present; - bool additional_update_result_present; - bool t3412_ext_present;v -}LIBLTE_MME_TRACKING_AREA_UPDATE_ACCEPT_MSG_STRUCT; - */ - - - //Send reply to eNB - //*reply_flag = true; - return true; } @@ -1256,7 +1201,6 @@ s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg m_s1ap_log->info("User not found. IMSI %015lu\n", emm_ctx->imsi); return false; } - //Pack NAS Authentication Request in Downlink NAS Transport msg pack_authentication_request(reply_msg, ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id, autn, rand); @@ -1268,10 +1212,14 @@ s1ap_nas_transport::handle_authentication_failure(srslte::byte_buffer_t *nas_msg break; } - return true; - + return true; } - + /* +bool +s1ap_nas_transport::handle_detach_request(nas_msg, ue_ctx, reply_buffer, reply_flag) +{ + return true; + }*/ /*Packing/Unpacking helper functions*/ bool s1ap_nas_transport::pack_authentication_request(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t next_mme_ue_s1ap_id, uint8_t *autn, uint8_t *rand) From b73a4da8f91d740007d7ba5bd0e5ff4efcde2138 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 22 Mar 2018 18:54:06 +0000 Subject: [PATCH 100/143] Starting to add support to NAS detach request. --- srsepc/hdr/mme/s1ap_nas_transport.h | 7 +++ srsepc/src/mme/s1ap_nas_transport.cc | 78 ++++++++++++++++++++++++---- 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index 3827ab79d..5d6a07e37 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -74,6 +74,13 @@ public: bool* reply_flag, struct sctp_sndrcvinfo *enb_sri); + bool handle_nas_detach_request(uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + srslte::byte_buffer_t *nas_msg, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri); + bool handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag); bool handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index eb3fa85db..c1e532076 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -122,6 +122,26 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA handle_nas_service_request(ntohl(*m_tmsi), enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); return true; } + else if(msg_type == LIBLTE_MME_MSG_TYPE_DETACH_REQUEST) + { + m_s1ap_log->console("Received Detach Request\n"); + m_s1ap_log->info("Received Detach Request\n"); + if(!init_ue->S_TMSI_present) + { + m_s1ap_log->error("Service request -- S-TMSI not present\n"); + m_s1ap_log->console("Service request -- S-TMSI not present\n" ); + return false; + } + uint32_t *m_tmsi = (uint32_t*) &init_ue->S_TMSI.m_TMSI.buffer; + uint32_t enb_ue_s1ap_id = init_ue->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID; + m_s1ap_log->info("Detach Request -- S-TMSI 0x%x\n", ntohl(*m_tmsi)); + m_s1ap_log->console("Detach Request -- S-TMSI 0x%x\n", ntohl(*m_tmsi) ); + m_s1ap_log->info("Detach Request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); + m_s1ap_log->console("Detach Request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); + + handle_nas_detach_request(ntohl(*m_tmsi), enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); + return true; + } else { m_s1ap_log->info("Unhandled Initial UE Message 0x%x\n",msg_type); @@ -240,27 +260,25 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA } switch (msg_type) { case LIBLTE_MME_MSG_TYPE_ATTACH_COMPLETE: - m_s1ap_log->info("Uplink NAS: Received Attach Complete\n"); - m_s1ap_log->console("Uplink NAS: Received Attach Complete\n"); + m_s1ap_log->info("Integrity Protected UL NAS: Received Attach Complete\n"); + m_s1ap_log->console("Integrity Protected UL NAS: Received Attach Complete\n"); handle_nas_attach_complete(nas_msg, ue_ctx, reply_buffer, reply_flag); break; case LIBLTE_MME_MSG_TYPE_ESM_INFORMATION_RESPONSE: - m_s1ap_log->info("Uplink NAS: Received ESM Information Response\n"); - m_s1ap_log->console("Uplink NAS: Received ESM Information Response\n"); + m_s1ap_log->info("Integrity Protected UL NAS: Received ESM Information Response\n"); + m_s1ap_log->console("Integrity Protected UL NAS: Received ESM Information Response\n"); handle_esm_information_response(nas_msg, ue_ctx, reply_buffer, reply_flag); break; case LIBLTE_MME_MSG_TYPE_TRACKING_AREA_UPDATE_REQUEST: - m_s1ap_log->info("UL NAS: Tracking Area Update Request\n"); + m_s1ap_log->info("Integrity Protected UL NAS: Tracking Area Update Request\n"); + m_s1ap_log->console("Integrity Protected UL NAS: Tracking Area Update Request\n"); handle_tracking_area_update_request(nas_msg, ue_ctx, reply_buffer, reply_flag); break; case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_FAILURE: - m_s1ap_log->info("Uplink NAS: Authentication Failure\n"); + m_s1ap_log->info("Integrity Protected UL NAS: Authentication Failure\n"); + m_s1ap_log->info("Integrity Protected UL NAS: Authentication Failure\n"); handle_authentication_failure(nas_msg, ue_ctx, reply_buffer, reply_flag); break; - /* case LIBLTE_MME_MSG_TYPE_DETACH_REQUEST: - m_s1ap_log->info("Uplink NAS: Detach Request\n"); - handle_detach_request(nas_msg, ue_ctx, reply_buffer, reply_flag); - break;*/ default: m_s1ap_log->warning("Unhandled NAS integrity protected message 0x%x\n", msg_type ); m_s1ap_log->console("Unhandled NAS integrity protected message 0x%x\n", msg_type ); @@ -557,7 +575,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, else{ m_s1ap_log->console("Attach Request -- Found M-TMSI: %d\n",m_tmsi); - m_s1ap_log->console("Attach Request -- IMSI: %d\n",it->second); + m_s1ap_log->console("Attach Request -- IMSI: %015lu\n",it->second); //Get UE EMM context ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_imsi(it->second); if(ue_ctx!=NULL) @@ -569,8 +587,11 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, bool msg_valid = false; emm_ctx->security_ctxt.ul_nas_count++; msg_valid = integrity_check(emm_ctx,nas_msg); + + if(msg_valid == true) { + m_s1ap_log->console("GUTI Attach Integrity valid. UL count %d, DL count %d\n",emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.dl_nas_count); //Create new MME UE S1AP Identity uint32_t new_mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); @@ -609,6 +630,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, //Re-generate K_eNB liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); + m_s1ap_log->console("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); //Create session request m_s1ap_log->console("GUTI Attach -- NAS Integrity OK."); @@ -786,6 +808,39 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, return true; } +bool +s1ap_nas_transport::handle_nas_detach_request(uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + srslte::byte_buffer_t *nas_msg, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri) +{ + bool mac_valid = false; + LIBLTE_MME_DETACH_REQUEST_MSG_STRUCT detach_req; + + LIBLTE_ERROR_ENUM err = liblte_mme_unpack_detach_request_msg((LIBLTE_BYTE_MSG_STRUCT*) nas_msg, &detach_req); + if(err !=LIBLTE_SUCCESS) + { + m_s1ap_log->error("Could not unpack detach request\n"); + return false; + } + + std::map::iterator it = m_s1ap->m_tmsi_to_imsi.find(m_tmsi); + if(it == m_s1ap->m_tmsi_to_imsi.end()) + { + m_s1ap_log->console("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + m_s1ap_log->error("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + return true; + } + ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_imsi(it->second); + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); + emm_ctx->security_ctxt.ul_nas_count++; + return true; +} bool s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag) { @@ -882,6 +937,7 @@ s1ap_nas_transport::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas return true; } + bool s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { From d82c0b7f6b1a66251f4b09e115a9b71c99c6d287 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 22 Mar 2018 22:42:31 +0000 Subject: [PATCH 101/143] Adding handling of detach request. --- srsepc/hdr/mme/s1ap_nas_transport.h | 2 +- srsepc/src/mme/s1ap_nas_transport.cc | 67 ++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index 5d6a07e37..9f5b1b646 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -87,8 +87,8 @@ public: bool handle_esm_information_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); bool handle_identity_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); bool handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); - bool handle_authentication_failure(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); + bool handle_nas_detach_request(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag); bool integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu); bool short_integrity_check(ue_emm_ctx_t *emm_ctx, srslte::byte_buffer_t *pdu); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index c1e532076..6e8c3730f 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -124,8 +124,8 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA } else if(msg_type == LIBLTE_MME_MSG_TYPE_DETACH_REQUEST) { - m_s1ap_log->console("Received Detach Request\n"); - m_s1ap_log->info("Received Detach Request\n"); + m_s1ap_log->console("Received Initial UE message -- Detach Request\n"); + m_s1ap_log->info("Received Initial UE message -- Detach Request\n"); if(!init_ue->S_TMSI_present) { m_s1ap_log->error("Service request -- S-TMSI not present\n"); @@ -276,7 +276,12 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA break; case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_FAILURE: m_s1ap_log->info("Integrity Protected UL NAS: Authentication Failure\n"); - m_s1ap_log->info("Integrity Protected UL NAS: Authentication Failure\n"); + m_s1ap_log->console("Integrity Protected UL NAS: Authentication Failure\n"); + handle_authentication_failure(nas_msg, ue_ctx, reply_buffer, reply_flag); + break; + case LIBLTE_MME_MSG_TYPE_DETACH_REQUEST: + m_s1ap_log->info("Integrity Protected UL NAS: Detach Request\n"); + m_s1ap_log->console("Integrity Protected UL NAS: Detach Request\n"); handle_authentication_failure(nas_msg, ue_ctx, reply_buffer, reply_flag); break; default: @@ -582,35 +587,31 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, { ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; - m_s1ap_log->console("Found UE context. IMSI: %015lu, old MME UE S1AP Id %d\n",emm_ctx->imsi, ecm_ctx->mme_ue_s1ap_id); + m_s1ap_log->console("Found UE context. IMSI: %015lu, 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); //Check NAS integrity bool msg_valid = false; emm_ctx->security_ctxt.ul_nas_count++; msg_valid = integrity_check(emm_ctx,nas_msg); - if(msg_valid == true) { m_s1ap_log->console("GUTI Attach Integrity valid. UL count %d, DL count %d\n",emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.dl_nas_count); - //Create new MME UE S1AP Identity - uint32_t new_mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); - - //Make sure context from previous NAS connections is not present - if(ecm_ctx->mme_ue_s1ap_id!=0) + if(emm_ctx->state != EMM_STATE_DEREGISTERED) { - m_s1ap->release_ue_ecm_ctx(ecm_ctx->mme_ue_s1ap_id); + m_s1ap_log->error("Received Attach Request from attached user.\n"); + m_s1ap_log->console("Received Attach Request from attached user.\n"); + //FIXME handle error case + return false; } + //Create new MME UE S1AP Identity emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); ecm_ctx->mme_ue_s1ap_id = emm_ctx->mme_ue_s1ap_id; - //Set EMM as de-registered - emm_ctx->state = EMM_STATE_DEREGISTERED; + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + ecm_ctx->imsi = ecm_ctx->imsi; + //Save Attach type emm_ctx->attach_type = attach_req.eps_attach_type; - //Set UE ECM context - ecm_ctx->imsi = ecm_ctx->imsi; - ecm_ctx->mme_ue_s1ap_id = ecm_ctx->mme_ue_s1ap_id; - //Set eNB information ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; memcpy(&ecm_ctx->enb_sri, enb_sri, sizeof(struct sctp_sndrcvinfo)); @@ -788,7 +789,6 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, } m_s1ap_log->console("UE previously assigned IP: %s",inet_ntoa(emm_ctx->ue_ip)); - //Mark E-RABs as setup, but not active yet //Re-generate K_eNB liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); @@ -837,10 +837,39 @@ s1ap_nas_transport::handle_nas_detach_request(uint32_t m_tmsi, ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; - m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx,reply_buffer); + m_mme_gtpc->send_delete_session_request(emm_ctx->imsi); + emm_ctx->state = EMM_STATE_DEREGISTERED; emm_ctx->security_ctxt.ul_nas_count++; + + m_s1ap_log->console("Received. M-TMSI 0x%x\n", m_tmsi); + //Received detach request as an initial UE message + //No need to clear ECM context; the request would have been sent as Uplink NAS transport if it was present. return true; } + +//FIXME re-factor to reduce code duplication +bool +s1ap_nas_transport::handle_nas_detach_request(srslte::byte_buffer_t *nas_msg, ue_ctx_t* ue_ctx, srslte::byte_buffer_t *reply_msg, bool *reply_flag) +{ + + m_s1ap_log->console("Detach request -- IMSI %015lu", ue_ctx->emm_ctx.imsi); + m_s1ap_log->info("Detach request -- IMSI %015lu", ue_ctx->emm_ctx.imsi); + LIBLTE_MME_DETACH_REQUEST_MSG_STRUCT detach_req; + + LIBLTE_ERROR_ENUM err = liblte_mme_unpack_detach_request_msg((LIBLTE_BYTE_MSG_STRUCT*) nas_msg, &detach_req); + if(err !=LIBLTE_SUCCESS) + { + m_s1ap_log->error("Could not unpack detach request\n"); + return false; + } + + if(ue_ctx->ecm_ctx.mme_ue_s1ap_id!=0) + { + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(&ue_ctx->ecm_ctx, reply_msg); + } + return true; +} + bool s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag) { From 3bc2cb859c48789c31daa7ed6e1accfd7c8882fc Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 23 Mar 2018 16:50:41 +0000 Subject: [PATCH 102/143] Sending ESM information request when GUTI attach passes integrity checks. --- srsepc/src/mme/s1ap.cc | 4 +-- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 8 ++++-- srsepc/src/mme/s1ap_nas_transport.cc | 41 +++++++++++++++++++++++---- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 4bb71367b..c22870243 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -550,10 +550,10 @@ s1ap::activate_eps_bearer(uint64_t imsi, uint8_t ebi) uint32_t s1ap::allocate_m_tmsi(uint64_t imsi) { - uint32_t m_tmsi = m_next_m_tmsi++; + // uint32_t m_tmsi = m_next_m_tmsi++; + uint32_t m_tmsi = m_next_m_tmsi; m_tmsi_to_imsi.insert(std::pair(m_tmsi,imsi)); m_s1ap_log->debug("Allocated M-TMSI 0x%x to IMSI %015lu,\n",m_tmsi,imsi); - //uint32_t m_tmsi = 0x0123; return m_tmsi; } diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 6d8da0129..2938b128c 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -285,9 +285,13 @@ s1ap_ctx_mngmt_proc::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECON //There are active E-RABs, send release access mearers request m_s1ap_log->console("There are active E-RABs, send release access mearers request"); m_s1ap_log->info("There are active E-RABs, send release access mearers request"); - m_mme_gtpc->send_release_access_bearers_request(ecm_ctx->imsi); - //The handle_releease_access_bearers_response function will make sure to mark E-RABS DEACTIVATED + + //The handle_release_access_bearers_response function will make sure to mark E-RABS DEACTIVATED //It will release the UEs downstream S1-u and keep the upstream S1-U connection active. + m_mme_gtpc->send_release_access_bearers_request(ecm_ctx->imsi); + + //Send release context command to enb, so that it can release it's bearers + send_ue_context_release_command(ecm_ctx,reply_buffer); } else { diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 6e8c3730f..5e40cf219 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -592,7 +592,6 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, bool msg_valid = false; emm_ctx->security_ctxt.ul_nas_count++; msg_valid = integrity_check(emm_ctx,nas_msg); - if(msg_valid == true) { m_s1ap_log->console("GUTI Attach Integrity valid. UL count %d, DL count %d\n",emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.dl_nas_count); @@ -609,6 +608,7 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; ecm_ctx->imsi = ecm_ctx->imsi; + emm_ctx->procedure_transaction_id = pdn_con_req.proc_transaction_id; //Save Attach type emm_ctx->attach_type = attach_req.eps_attach_type; @@ -627,16 +627,40 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, //Store context based on MME UE S1AP id m_s1ap->add_ue_ctx_to_mme_ue_s1ap_id_map(ue_ctx); - + //Re-generate K_eNB liblte_security_generate_k_enb(emm_ctx->security_ctxt.k_asme, emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.k_enb); m_s1ap_log->info("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); m_s1ap_log->console("Generating KeNB with UL NAS COUNT: %d\n",emm_ctx->security_ctxt.ul_nas_count); + + m_s1ap_log->console("Attach request -- IMSI: %015lu\n", ecm_ctx->imsi); + m_s1ap_log->info("Attach request -- IMSI: %015lu\n", ecm_ctx->imsi); + m_s1ap_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id); + m_s1ap_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]); + m_s1ap_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]); + m_s1ap_log->console("Attach Request -- MS Network Capabilities Present: %s\n", attach_req.ms_network_cap_present ? "true" : "false"); + m_s1ap_log->console("PDN Connectivity Request -- EPS Bearer Identity requested: %d\n", pdn_con_req.eps_bearer_id); + m_s1ap_log->console("PDN Connectivity Request -- Procedure Transaction Id: %d\n", pdn_con_req.proc_transaction_id); + m_s1ap_log->console("PDN Connectivity Request -- ESM Information Transfer requested: %s\n", pdn_con_req.esm_info_transfer_flag_present ? "true" : "false"); //Create session request - m_s1ap_log->console("GUTI Attach -- NAS Integrity OK."); - m_mme_gtpc->send_create_session_request(emm_ctx->imsi); - *reply_flag = false; //No reply needed + m_s1ap_log->console("GUTI Attach -- NAS Integrity OK.\n"); + if(ecm_ctx->eit) + { + m_s1ap_log->console("Secure ESM information transfer requested.\n"); + m_s1ap_log->info("Secure ESM information transfer requested.\n"); + pack_esm_information_request(reply_buffer, emm_ctx, ecm_ctx); + *reply_flag = true; + } + else + { + m_mme_gtpc->send_create_session_request(emm_ctx->imsi); + *reply_flag = false; //No reply needed + } return true; } else @@ -843,7 +867,10 @@ s1ap_nas_transport::handle_nas_detach_request(uint32_t m_tmsi, m_s1ap_log->console("Received. M-TMSI 0x%x\n", m_tmsi); //Received detach request as an initial UE message - //No need to clear ECM context; the request would have been sent as Uplink NAS transport if it was present. + //eNB created new ECM context to send the detach request; this needs to be cleared. + ecm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx, reply_buffer); return true; } @@ -863,6 +890,8 @@ s1ap_nas_transport::handle_nas_detach_request(srslte::byte_buffer_t *nas_msg, ue return false; } + m_mme_gtpc->send_delete_session_request(ue_ctx->emm_ctx.imsi); + ue_ctx->emm_ctx.state = EMM_STATE_DEREGISTERED; if(ue_ctx->ecm_ctx.mme_ue_s1ap_id!=0) { m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(&ue_ctx->ecm_ctx, reply_msg); From 45a1e8425b98e663c5b6f76e0eeede5c11e62d02 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 23 Mar 2018 17:15:27 +0000 Subject: [PATCH 103/143] Fix bug in dettach request from UL Nas transport --- srsepc/src/mme/s1ap_nas_transport.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 5e40cf219..d497ca30f 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -282,7 +282,7 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA case LIBLTE_MME_MSG_TYPE_DETACH_REQUEST: m_s1ap_log->info("Integrity Protected UL NAS: Detach Request\n"); m_s1ap_log->console("Integrity Protected UL NAS: Detach Request\n"); - handle_authentication_failure(nas_msg, ue_ctx, reply_buffer, reply_flag); + handle_nas_detach_request(nas_msg, ue_ctx, reply_buffer, reply_flag); break; default: m_s1ap_log->warning("Unhandled NAS integrity protected message 0x%x\n", msg_type ); @@ -894,7 +894,7 @@ s1ap_nas_transport::handle_nas_detach_request(srslte::byte_buffer_t *nas_msg, ue ue_ctx->emm_ctx.state = EMM_STATE_DEREGISTERED; if(ue_ctx->ecm_ctx.mme_ue_s1ap_id!=0) { - m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(&ue_ctx->ecm_ctx, reply_msg); + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(&ue_ctx->ecm_ctx, reply_msg); } return true; } From fb1e87cf53b5f332c1fc1cc2f5a0fefdbfdcb015 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Sat, 24 Mar 2018 14:59:22 +0000 Subject: [PATCH 104/143] Fixing bug for IMSI attach of already attached user. --- srsepc/src/mme/s1ap_nas_transport.cc | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index d497ca30f..34fc3e436 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -374,10 +374,27 @@ s1ap_nas_transport::handle_nas_imsi_attach_request(uint32_t enb_ue_s1ap_id, ue_ecm_ctx_t *ecm_ctx = &ue_ctx.ecm_ctx; //Set UE's EMM context - emm_ctx->imsi = 0; + uint64_t imsi = 0; for(int i=0;i<=14;i++){ - emm_ctx->imsi += attach_req.eps_mobile_id.imsi[i]*std::pow(10,14-i); + imsi += attach_req.eps_mobile_id.imsi[i]*std::pow(10,14-i); } + + //Check if UE is + ue_ctx_t *old_ctx = m_s1ap->find_ue_ctx_from_imsi(imsi); + if(old_ctx!=NULL) + { + m_s1ap_log->console("Attach Request -- UE is already attached."); + m_s1ap_log->info("Attach Request -- UE is already attached."); + //Detaching previoulsy attached UE. + m_mme_gtpc->send_delete_session_request(imsi); + if(old_ctx->ecm_ctx.mme_ue_s1ap_id!=0) + { + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(&old_ctx->ecm_ctx, reply_buffer); + } + m_s1ap->delete_ue_ctx(imsi); + } + + emm_ctx->imsi = imsi; emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); emm_ctx->state = EMM_STATE_DEREGISTERED; //Save UE network capabilities From ea8e7c9301800f3b2bcc173488bc91eda96a895d Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Sat, 24 Mar 2018 16:31:29 +0000 Subject: [PATCH 105/143] Fixed bug in GUTI attach when UE is already attached. --- srsepc/src/mme/s1ap_nas_transport.cc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 34fc3e436..881d1b386 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -609,16 +609,10 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, bool msg_valid = false; emm_ctx->security_ctxt.ul_nas_count++; msg_valid = integrity_check(emm_ctx,nas_msg); - if(msg_valid == true) + if(msg_valid == true && emm_ctx->state == EMM_STATE_DEREGISTERED) { m_s1ap_log->console("GUTI Attach Integrity valid. UL count %d, DL count %d\n",emm_ctx->security_ctxt.ul_nas_count, emm_ctx->security_ctxt.dl_nas_count); - if(emm_ctx->state != EMM_STATE_DEREGISTERED) - { - m_s1ap_log->error("Received Attach Request from attached user.\n"); - m_s1ap_log->console("Received Attach Request from attached user.\n"); - //FIXME handle error case - return false; - } + //Create new MME UE S1AP Identity emm_ctx->mme_ue_s1ap_id = m_s1ap->get_next_mme_ue_s1ap_id(); ecm_ctx->mme_ue_s1ap_id = emm_ctx->mme_ue_s1ap_id; @@ -682,6 +676,19 @@ s1ap_nas_transport::handle_nas_guti_attach_request( uint32_t enb_ue_s1ap_id, } else { + if(emm_ctx->state != EMM_STATE_DEREGISTERED) + { + m_s1ap_log->error("Received GUTI-Attach Request from attached user.\n"); + m_s1ap_log->console("Received GUTI-Attach Request from attached user.\n"); + + //Delete previous Ctx, restart authentication + //Detaching previoulsy attached UE. + m_mme_gtpc->send_delete_session_request(emm_ctx->imsi); + if(ecm_ctx->mme_ue_s1ap_id!=0) + { + m_s1ap->m_s1ap_ctx_mngmt_proc->send_ue_context_release_command(ecm_ctx, reply_buffer); + } + } emm_ctx->security_ctxt.ul_nas_count = 0; emm_ctx->security_ctxt.dl_nas_count = 0; From cb0f7fc8c2574c222a3ca3938df5c60ba782d523 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Sat, 24 Mar 2018 16:36:13 +0000 Subject: [PATCH 106/143] Changed print when service request integrity fails. --- srsepc/src/mme/s1ap_nas_transport.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 881d1b386..2d11384ae 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -849,9 +849,8 @@ s1ap_nas_transport::handle_nas_service_request(uint32_t m_tmsi, } else { - m_s1ap_log->console("Service Request -- Short MAC invalid. Re-starting authentication procedure \n"); - m_s1ap_log->console("Service Request -- Short MAC invalid. Re-starting authentication procedure \n"); - m_s1ap_log->console("Authentication procedure is not restarted yet!\n"); + m_s1ap_log->console("Service Request -- Short MAC invalid. Ignoring service request\n"); + m_s1ap_log->console("Service Request -- Short MAC invalid. Ignoring service request\n"); } return true; } From ff103dc4cda0db0ed110e8e1f24513d0e3360423 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 26 Mar 2018 11:01:28 +0100 Subject: [PATCH 107/143] Remove debig prints --- srsepc/src/spgw/spgw.cc | 9 --------- 1 file changed, 9 deletions(-) diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index e35a99be3..191e131df 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -387,15 +387,6 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg) { m_spgw_log->error("Mis-match between packet bytes and sent bytes: Sent: %d, Packet: %d \n",n,msg->N_bytes); } - - gettimeofday(&t_now, NULL); - t_delta.tv_sec = t_now.tv_sec - m_t_last_dl.tv_sec; - t_delta.tv_usec = t_now.tv_sec - m_t_last_dl.tv_usec; - if(t_delta.tv_sec>=5) - { - m_t_last_dl = t_now; - m_spgw_log->console("Sent %d bytes DL over the last %d.%d seconds. Bitrate = \n",msg->N_bytes, t_delta.tv_sec, t_delta.tv_usec/1000); - } return; } From 57220bd6a8bb52d6f3ecbb6c9f03dcbb158ff64f Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 26 Mar 2018 11:25:13 +0100 Subject: [PATCH 108/143] Fixed compiler warnings. --- lib/src/asn1/liblte_mme.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/asn1/liblte_mme.cc b/lib/src/asn1/liblte_mme.cc index da79fb791..6d9dedcdc 100644 --- a/lib/src/asn1/liblte_mme.cc +++ b/lib/src/asn1/liblte_mme.cc @@ -296,10 +296,10 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_mobile_id_ie(LIBLTE_MME_MOBILE_ID_STRUCT *mob uint8 **ie_ptr) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; - uint8 *id; - uint32 id32; + uint8 *id = NULL; + uint32 id32 = 0; uint32 i; - uint8 length; + uint8 length = 0; bool odd = false; if(mobile_id != NULL && From b1f4ee47d1bbb9b1e05a3923e879470521073fed Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 26 Mar 2018 11:58:35 +0100 Subject: [PATCH 109/143] Temporally removed unhandled UE cap info. --- srsepc/hdr/mme/s1ap.h | 2 - srsepc/hdr/mme/s1ap_ue_cap_info.h | 58 ---------------------- srsepc/src/mme/s1ap.cc | 10 +--- srsepc/src/mme/s1ap_ue_cap_info.cc | 78 ------------------------------ 4 files changed, 1 insertion(+), 147 deletions(-) delete mode 100644 srsepc/hdr/mme/s1ap_ue_cap_info.h delete mode 100644 srsepc/src/mme/s1ap_ue_cap_info.cc diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index d417d9442..31ea68436 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -44,7 +44,6 @@ #include "mme/s1ap_mngmt_proc.h" #include "mme/s1ap_nas_transport.h" #include "mme/s1ap_ctx_mngmt_proc.h" -#include "mme/s1ap_ue_cap_info.h" #include "mme/mme_gtpc.h" #include "hss/hss.h" @@ -112,7 +111,6 @@ public: s1ap_mngmt_proc* m_s1ap_mngmt_proc; s1ap_nas_transport* m_s1ap_nas_transport; s1ap_ctx_mngmt_proc* m_s1ap_ctx_mngmt_proc; - s1ap_ue_cap_info* m_s1ap_ue_cap_info; std::map m_tmsi_to_imsi; diff --git a/srsepc/hdr/mme/s1ap_ue_cap_info.h b/srsepc/hdr/mme/s1ap_ue_cap_info.h deleted file mode 100644 index 4e3b4c14e..000000000 --- a/srsepc/hdr/mme/s1ap_ue_cap_info.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - * - * \section COPYRIGHT - * - * Copyright 2013-2017 Software Radio Systems Limited - * - * \section LICENSE - * - * This file is part of srsLTE. - * - * srsLTE is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * srsLTE is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * A copy of the GNU Affero General Public License can be found in - * the LICENSE file in the top-level directory of this distribution - * and at http://www.gnu.org/licenses/. - * - */ -#ifndef S1AP_UE_CAP_INFO_H -#define S1AP_UE_CAP_INFO_H - -#include "srslte/asn1/liblte_s1ap.h" -#include "srslte/common/common.h" -#include "mme/s1ap_common.h" -#include "srslte/common/log_filter.h" - -namespace srsepc{ - -class s1ap; - -class s1ap_ue_cap_info -{ -public: - - static s1ap_ue_cap_info *m_instance; - - static s1ap_ue_cap_info* get_instance(void); - static void cleanup(void); - void init(void); - - bool handle_ue_capability_info_indication(LIBLTE_S1AP_MESSAGE_UECAPABILITYINFOINDICATION_STRUCT *msg, sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); - -private: - s1ap_ue_cap_info(); - virtual ~s1ap_ue_cap_info(); - - s1ap* m_s1ap; - srslte::log_filter *m_s1ap_log; -}; -} //namespace srsepc -#endif diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index c22870243..3fe34806c 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -92,9 +92,6 @@ s1ap::init(s1ap_args_t s1ap_args, srslte::log_filter *s1ap_log, hss_interface_s1 m_s1ap_nas_transport->init(m_hss); m_s1ap_ctx_mngmt_proc = s1ap_ctx_mngmt_proc::get_instance(); //Context Management Procedures m_s1ap_ctx_mngmt_proc->init(); - m_s1ap_ue_cap_info = s1ap_ue_cap_info::get_instance(); //UE Capability Information - m_s1ap_ue_cap_info->init(); - //Get pointer to GTP-C class m_mme_gtpc = mme_gtpc::get_instance(); @@ -132,7 +129,6 @@ s1ap::stop() s1ap_mngmt_proc::cleanup(); s1ap_nas_transport::cleanup(); s1ap_ctx_mngmt_proc::cleanup(); - s1ap_ue_cap_info::cleanup(); return; } @@ -142,7 +138,7 @@ s1ap::get_s1_mme() return m_s1mme; } -uint32_t +uint32_t s1ap::get_next_mme_ue_s1ap_id() { return m_next_mme_ue_s1ap_id++; @@ -256,10 +252,6 @@ s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, stru 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); break; - case LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_UECAPABILITYINFOINDICATION: - m_s1ap_log->info("Received UE Context Release Request Message.\n"); - m_s1ap_ue_cap_info->handle_ue_capability_info_indication(&msg->choice.UECapabilityInfoIndication, enb_sri, reply_buffer, &reply_flag); - break; default: m_s1ap_log->error("Unhandled S1AP intiating message: %s\n", liblte_s1ap_initiatingmessage_choice_text[msg->choice_type]); m_s1ap_log->console("Unhandled S1APintiating message: %s\n", liblte_s1ap_initiatingmessage_choice_text[msg->choice_type]); diff --git a/srsepc/src/mme/s1ap_ue_cap_info.cc b/srsepc/src/mme/s1ap_ue_cap_info.cc deleted file mode 100644 index f06fde165..000000000 --- a/srsepc/src/mme/s1ap_ue_cap_info.cc +++ /dev/null @@ -1,78 +0,0 @@ -/** - * - * \section COPYRIGHT - * - * Copyright 2013-2017 Software Radio Systems Limited - * - * \section LICENSE - * - * This file is part of srsLTE. - * - * srsLTE is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * srsLTE is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * A copy of the GNU Affero General Public License can be found in - * the LICENSE file in the top-level directory of this distribution - * and at http://www.gnu.org/licenses/. - * - */ -#include "mme/s1ap.h" -#include "mme/s1ap_ue_cap_info.h" - -namespace srsepc{ - -s1ap_ue_cap_info* s1ap_ue_cap_info::m_instance = NULL; -boost::mutex s1ap_ue_cap_info_instance_mutex; - - -s1ap_ue_cap_info::s1ap_ue_cap_info() -{ -} - -s1ap_ue_cap_info::~s1ap_ue_cap_info() -{ -} - -s1ap_ue_cap_info* -s1ap_ue_cap_info::get_instance(void) -{ - boost::mutex::scoped_lock lock(s1ap_ue_cap_info_instance_mutex); - if(NULL == m_instance) { - m_instance = new s1ap_ue_cap_info(); - } - return(m_instance); -} - -void -s1ap_ue_cap_info::cleanup(void) -{ - boost::mutex::scoped_lock lock(s1ap_ue_cap_info_instance_mutex); - if(NULL != m_instance) { - delete m_instance; - m_instance = NULL; - } -} - -void -s1ap_ue_cap_info::init(void) -{ - m_s1ap = s1ap::get_instance(); - m_s1ap_log = m_s1ap->m_s1ap_log; -} - -bool -s1ap_ue_cap_info::handle_ue_capability_info_indication(LIBLTE_S1AP_MESSAGE_UECAPABILITYINFOINDICATION_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) -{ - m_s1ap_log->info("UE Capability Info Indication\n"); - m_s1ap_log->console("UE Capability Info Indication\n"); - return true; -} - -} //namespace srsepc From 0435e996f377fd7348d8ef49cd15832af43649bb Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Mon, 26 Mar 2018 13:09:48 +0200 Subject: [PATCH 110/143] print PUSCH payload as hex --- srsue/src/phy/phch_worker.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index cb27a5000..47fdb9591 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -1108,7 +1108,8 @@ void phch_worker::encode_pusch(srslte_ra_ul_grant_t *grant, uint8_t *payload, ui srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, SRSLTE_CQI_STR_MAX_CHAR); uint8_t dummy[2] = {0,0}; - log_h->info("PUSCH: tti_tx=%d, alloc=(%d,%d), tbs=%d, mcs=%d, rv=%d%s%s%s, cfo=%.1f KHz%s%s%s\n", + log_h->info_hex(payload, grant->mcs.tbs/8, + "PUSCH: tti_tx=%d, alloc=(%d,%d), tbs=%d, mcs=%d, rv=%d%s%s%s, cfo=%.1f KHz%s%s%s\n", (tti + HARQ_DELAY_MS) % 10240, grant->n_prb[0], grant->n_prb[0] + grant->L_prb, grant->mcs.tbs / 8, grant->mcs.idx, rv, From 4ad02545b3a77f85268f67b123f854db633685e0 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Mon, 26 Mar 2018 13:10:38 +0200 Subject: [PATCH 111/143] fix printing issue in UM --- lib/src/upper/rlc_um.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/upper/rlc_um.cc b/lib/src/upper/rlc_um.cc index 6bbefaf78..6bad2a2cb 100644 --- a/lib/src/upper/rlc_um.cc +++ b/lib/src/upper/rlc_um.cc @@ -173,7 +173,7 @@ uint32_t rlc_um::get_bearer() void rlc_um::write_sdu(byte_buffer_t *sdu) { tx_sdu_queue.write(sdu); - log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU (% B ,tx_sdu_queue_len=%d)", rrc->get_rb_name(lcid).c_str(), sdu->N_bytes, tx_sdu_queue.size()); + log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU (%d B ,tx_sdu_queue_len=%d)", rrc->get_rb_name(lcid).c_str(), sdu->N_bytes, tx_sdu_queue.size()); } /**************************************************************************** From 902feeda285320454e13533590417aeb34415518 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Mon, 26 Mar 2018 13:13:47 +0200 Subject: [PATCH 112/143] fix printf in s1ap --- srsepc/src/mme/s1ap_nas_transport.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 5f791caa5..4cd29703b 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -118,12 +118,12 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA } else if(msg_type == LIBLTE_MME_SECURITY_HDR_TYPE_SERVICE_REQUEST) { - m_s1ap_log->info("Received Service Request \n"); - m_s1ap_log->console("Received Service Request \n"); + m_s1ap_log->info("Received Service Request\n"); + m_s1ap_log->console("Received Service Request\n"); liblte_mme_unpack_service_request_msg((LIBLTE_BYTE_MSG_STRUCT*) nas_msg, &service_req); - m_s1ap_log->info("Service Request not implemented. Sending Service Reject."); - m_s1ap_log->console("Service Request not implemented. Sending Service Reject."); + m_s1ap_log->info("Service Request not implemented. Sending Service Reject.\n"); + m_s1ap_log->console("Service Request not implemented. Sending Service Reject.\n"); /* Force UE to re-attach */ pack_service_reject(reply_buffer, LIBLTE_MME_EMM_CAUSE_IMPLICITLY_DETACHED, enb_ue_s1ap_id); *reply_flag = true; From e5534d601781cd51c10cd71cdbeb688ee397733c Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Mon, 26 Mar 2018 21:11:39 +0200 Subject: [PATCH 113/143] Remove leftovers from merge --- srsepc/epc.conf.example | 3 --- 1 file changed, 3 deletions(-) diff --git a/srsepc/epc.conf.example b/srsepc/epc.conf.example index 767c0620c..7fabca584 100644 --- a/srsepc/epc.conf.example +++ b/srsepc/epc.conf.example @@ -10,12 +10,9 @@ # tac: 16-bit Tracking Area Code. # mcc: Mobile Country Code # mnc: Mobile Network Code -<<<<<<< HEAD # mme_bindx_addr: IP subnet to listen for eNB S1 connnections # apn: Set Access Point Name (APN) -======= # mme_bind_addr: IP bind addr to listen for eNB S1 connnections ->>>>>>> epc # ##################################################################### [mme] From 0ac766658a6973e3500fd894da2a7b4d5f32f7d9 Mon Sep 17 00:00:00 2001 From: Eric Schreiber Date: Mon, 26 Mar 2018 17:21:07 -0400 Subject: [PATCH 114/143] Initialize the E_RABFailedToSetupListCtxtSURes_present and CriticalityDiagnostics_present members of the LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT to false to prevent "[S1AP] [E] Failed to send InitialContextSetupResponse" errors. When these members are set to false the liblte_s1ap_pack_initialcontextsetupresponse routine ignores the corresponding (uninitialized) structures when serializing the response pdu. --- srsenb/src/upper/rrc.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/srsenb/src/upper/rrc.cc b/srsenb/src/upper/rrc.cc index f1ae51016..e025dfca4 100644 --- a/srsenb/src/upper/rrc.cc +++ b/srsenb/src/upper/rrc.cc @@ -1069,6 +1069,9 @@ void rrc::ue::notify_s1ap_ue_ctxt_setup_complete() { LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT res; res.ext = false; + res.E_RABFailedToSetupListCtxtSURes_present = false; + res.CriticalityDiagnostics_present = false; + res.E_RABSetupListCtxtSURes.len = 0; res.E_RABFailedToSetupListCtxtSURes.len = 0; From 49a830e5481a61d154270365dbd9f4879a7f8a0e Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 28 Mar 2018 11:02:41 +0100 Subject: [PATCH 115/143] Making sure TAU requests are counted. --- srsepc/hdr/mme/s1ap_nas_transport.h | 7 ++++ srsepc/src/mme/s1ap_nas_transport.cc | 49 ++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index 9f5b1b646..500f41565 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -81,6 +81,13 @@ public: bool* reply_flag, struct sctp_sndrcvinfo *enb_sri); + bool handle_nas_tracking_area_update_request( uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + srslte::byte_buffer_t *nas_msg, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri); + bool handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag); bool handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); bool handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 2d11384ae..eb64a09eb 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -128,8 +128,8 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA m_s1ap_log->info("Received Initial UE message -- Detach Request\n"); if(!init_ue->S_TMSI_present) { - m_s1ap_log->error("Service request -- S-TMSI not present\n"); - m_s1ap_log->console("Service request -- S-TMSI not present\n" ); + m_s1ap_log->error("Detach request -- S-TMSI not present\n"); + m_s1ap_log->console("Detach request -- S-TMSI not present\n" ); return false; } uint32_t *m_tmsi = (uint32_t*) &init_ue->S_TMSI.m_TMSI.buffer; @@ -142,6 +142,26 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA handle_nas_detach_request(ntohl(*m_tmsi), enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); return true; } + else if(msg_type == 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"); + if(!init_ue->S_TMSI_present) + { + m_s1ap_log->error("Tracking Area Update Request -- S-TMSI not present\n"); + m_s1ap_log->console("Tracking Area Update Request -- S-TMSI not present\n" ); + return false; + } + uint32_t *m_tmsi = (uint32_t*) &init_ue->S_TMSI.m_TMSI.buffer; + uint32_t enb_ue_s1ap_id = init_ue->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID; + m_s1ap_log->info("Tracking Area Update Request -- S-TMSI 0x%x\n", ntohl(*m_tmsi)); + m_s1ap_log->console("Tracking Area Update Request -- S-TMSI 0x%x\n", ntohl(*m_tmsi) ); + m_s1ap_log->info("Tracking Area Update Request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); + m_s1ap_log->console("Tracking Area Update Request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); + + handle_nas_tracking_area_update_request(ntohl(*m_tmsi), enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); + return true; + } else { m_s1ap_log->info("Unhandled Initial UE Message 0x%x\n",msg_type); @@ -922,6 +942,31 @@ s1ap_nas_transport::handle_nas_detach_request(srslte::byte_buffer_t *nas_msg, ue return true; } +bool +s1ap_nas_transport::handle_nas_tracking_area_update_request(uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + srslte::byte_buffer_t *nas_msg, + srslte::byte_buffer_t *reply_buffer, + bool* reply_flag, + struct sctp_sndrcvinfo *enb_sri) +{ + m_s1ap_log->console("Warning: Tracking area update requests are not handled yet.\n"); + m_s1ap_log->warning("Tracking area update requests are not handled yet.\n"); + + std::map::iterator it = m_s1ap->m_tmsi_to_imsi.find(m_tmsi); + if(it == m_s1ap->m_tmsi_to_imsi.end()) + { + m_s1ap_log->console("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + m_s1ap_log->error("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + return true; + } + ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_imsi(it->second); + ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; + ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; + + emm_ctx->security_ctxt.ul_nas_count++;//Increment the NAS count, not to break the security ctx + return true; +} bool s1ap_nas_transport::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, ue_ctx_t *ue_ctx, srslte::byte_buffer_t *reply_buffer, bool* reply_flag) { From 09ac36a618eeaed51581a622e00e633e17a626ba Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 28 Mar 2018 12:01:15 +0100 Subject: [PATCH 116/143] Making sure DNS address is present in the epc.conf --- srsepc/epc.conf.example | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/srsepc/epc.conf.example b/srsepc/epc.conf.example index 7fabca584..02ef797ef 100644 --- a/srsepc/epc.conf.example +++ b/srsepc/epc.conf.example @@ -10,9 +10,9 @@ # tac: 16-bit Tracking Area Code. # mcc: Mobile Country Code # mnc: Mobile Network Code -# mme_bindx_addr: IP subnet to listen for eNB S1 connnections -# apn: Set Access Point Name (APN) -# mme_bind_addr: IP bind addr to listen for eNB S1 connnections +# apn: Set Access Point Name (APN) +# mme_bind_addr: IP bind addr to listen for eNB S1-MME connnections +# dns_addr: DNS server address for the UEs # ##################################################################### [mme] @@ -23,6 +23,7 @@ mcc = 001 mnc = 01 mme_bind_addr = 127.0.1.100 apn = srsapn +dns_addr = 8.8.8.8 ##################################################################### # HSS configuration From b50672b0ef1da4903c3b327f41f6eb935bce6b93 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Wed, 28 Mar 2018 16:41:10 +0200 Subject: [PATCH 117/143] fix non-returning function warning --- srsue/src/upper/nas.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/srsue/src/upper/nas.cc b/srsue/src/upper/nas.cc index 7069f4a23..939db1686 100644 --- a/srsue/src/upper/nas.cc +++ b/srsue/src/upper/nas.cc @@ -376,6 +376,7 @@ bool nas::integrity_check(byte_buffer_t *pdu) return true; } else { nas_log->error("Invalid integrity check PDU size (%d)\n", pdu->N_bytes); + return false; } } From bf25a5a05cfbc56128e2bbd1df00a1c3da18ea52 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Wed, 28 Mar 2018 16:46:40 +0200 Subject: [PATCH 118/143] fix handling of log vector in eNB --- srsenb/hdr/enb.h | 2 +- srsenb/hdr/phy/phy.h | 5 +++-- srsenb/src/enb.cc | 5 ++++- srsenb/src/phy/phy.cc | 10 +++++----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/srsenb/hdr/enb.h b/srsenb/hdr/enb.h index ff314977a..6d2a78b44 100644 --- a/srsenb/hdr/enb.h +++ b/srsenb/hdr/enb.h @@ -188,7 +188,7 @@ private: srslte::logger *logger; srslte::log_filter rf_log; - std::vector phy_log; + std::vector phy_log; srslte::log_filter mac_log; srslte::log_filter rlc_log; srslte::log_filter pdcp_log; diff --git a/srsenb/hdr/phy/phy.h b/srsenb/hdr/phy/phy.h index a1616c268..99b23de0c 100644 --- a/srsenb/hdr/phy/phy.h +++ b/srsenb/hdr/phy/phy.h @@ -28,6 +28,7 @@ #define ENBPHY_H #include "srslte/common/log.h" +#include "srslte/common/log_filter.h" #include "phy/txrx.h" #include "phy/phch_worker.h" #include "phy/phch_common.h" @@ -54,8 +55,8 @@ class phy : public phy_interface_mac, public: phy(); - bool init(phy_args_t *args, phy_cfg_t *common_cfg, srslte::radio *radio_handler, mac_interface_phy *mac, srslte::log* log_h); - bool init(phy_args_t *args, phy_cfg_t *common_cfg, srslte::radio *radio_handler, mac_interface_phy *mac, std::vector log_vec); + bool init(phy_args_t *args, phy_cfg_t *common_cfg, srslte::radio *radio_handler, mac_interface_phy *mac, srslte::log_filter* log_h); + bool init(phy_args_t *args, phy_cfg_t *common_cfg, srslte::radio *radio_handler, mac_interface_phy *mac, std::vector log_vec); void stop(); /* MAC->PHY interface */ diff --git a/srsenb/src/enb.cc b/srsenb/src/enb.cc index 564775e5e..6e5e06669 100644 --- a/srsenb/src/enb.cc +++ b/srsenb/src/enb.cc @@ -67,6 +67,9 @@ enb::enb() : started(false) { enb::~enb() { + for (uint32_t i = 0; i < phy_log.size(); i++) { + delete (phy_log[i]); + } } bool enb::init(all_args_t *args_) @@ -89,7 +92,7 @@ bool enb::init(all_args_t *args_) char tmp[16]; sprintf(tmp, "PHY%d",i); mylog->init(tmp, logger, true); - phy_log.push_back((void*) mylog); + phy_log.push_back(mylog); } mac_log.init("MAC ", logger, true); rlc_log.init("RLC ", logger); diff --git a/srsenb/src/phy/phy.cc b/srsenb/src/phy/phy.cc index d47998fa9..08b89d77f 100644 --- a/srsenb/src/phy/phy.cc +++ b/srsenb/src/phy/phy.cc @@ -92,12 +92,12 @@ void phy::parse_config(phy_cfg_t* cfg) bool phy::init(phy_args_t *args, phy_cfg_t *cfg, srslte::radio* radio_handler_, - mac_interface_phy *mac, - srslte::log* log_h) + mac_interface_phy *mac, + srslte::log_filter* log_h) { - std::vector log_vec; + std::vector log_vec; for (int i=0;inof_phy_threads;i++) { - log_vec.push_back((void*)log_h); + log_vec.push_back(log_h); } init(args, cfg, radio_handler_, mac, log_vec); return true; @@ -107,7 +107,7 @@ bool phy::init(phy_args_t *args, phy_cfg_t *cfg, srslte::radio* radio_handler_, mac_interface_phy *mac, - std::vector log_vec) + std::vector log_vec) { mlockall(MCL_CURRENT | MCL_FUTURE); From fffda82f1ee3c48175274e2ff67fcecc244ef06c Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 23 Mar 2018 16:41:37 +0100 Subject: [PATCH 119/143] increase size of bytebuffer to compensate header, add helper to get remaining size --- lib/include/srslte/common/common.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/include/srslte/common/common.h b/lib/include/srslte/common/common.h index 8089634b7..de9f6d5aa 100644 --- a/lib/include/srslte/common/common.h +++ b/lib/include/srslte/common/common.h @@ -147,6 +147,11 @@ public: { return msg-buffer; } + // Returns the remaining space from what is reported to be the length of msg + uint32_t get_tailroom() + { + return (sizeof(buffer) - (msg-buffer) - N_bytes); + } long get_latency_us() { #ifdef ENABLE_TIMESTAMP From 6063888cc5d7435f3f597cf0938154e22c63099a Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 27 Mar 2018 21:33:26 +0200 Subject: [PATCH 120/143] protect memcpy's in rx sdu reassembly with boundary checks --- lib/src/upper/rlc_am.cc | 75 +++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 5c7cb72ea..d100508d1 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -128,10 +128,10 @@ void rlc_am::reset() reordering_timeout.reset(); if(tx_sdu) { pool->deallocate(tx_sdu); - tx_sdu = NULL; } - if(rx_sdu) - rx_sdu->reset(); + if(rx_sdu) { + pool->deallocate(rx_sdu); + } vt_a = 0; vt_ms = RLC_AM_WINDOW_SIZE; @@ -827,6 +827,12 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes) rrc->get_rb_name(lcid).c_str(), to_move, pdu_space, head_len); } + // Make sure, at least one SDU (segment) has been added until this point + if (pdu->N_bytes == 0) { + log->error("Generated empty RLC PDU.\n"); + return 0; + } + if(tx_sdu) header.fi |= RLC_FI_FIELD_NOT_END_ALIGNED; // Last byte does not correspond to last byte of SDU @@ -848,7 +854,6 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes) // Set SN header.sn = vt_s; vt_s = (vt_s + 1)%MOD; - log->info("%s PDU scheduled for tx. SN: %d (%d B)\n", rrc->get_rb_name(lcid).c_str(), header.sn, pdu->N_bytes); // Place PDU in tx_window, write header and TX tx_window[header.sn].buf = pdu; @@ -859,6 +864,7 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes) uint8_t *ptr = payload; rlc_am_write_data_pdu_header(&header, &ptr); memcpy(ptr, pdu->msg, pdu->N_bytes); + log->info_hex(payload, pdu->N_bytes, "%s PDU scheduled for tx. SN: %d (%d B)\n", rrc->get_rb_name(lcid).c_str(), header.sn, pdu->N_bytes); debug_state(); return (ptr-payload) + pdu->N_bytes; @@ -868,8 +874,8 @@ void rlc_am::handle_data_pdu(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_h { std::map::iterator it; - log->info_hex(payload, nof_bytes, "%s Rx data PDU SN: %d", - rrc->get_rb_name(lcid).c_str(), header.sn); + log->info_hex(payload, nof_bytes, "%s Rx data PDU SN: %d (%d B), %s", + rrc->get_rb_name(lcid).c_str(), header.sn, nof_bytes, rlc_fi_field_text[header.fi]); if(!inside_rx_window(header.sn)) { if(header.p) { @@ -1157,38 +1163,55 @@ void rlc_am::reassemble_rx_sdus() #endif } } + // Iterate through rx_window, assembling and delivering SDUs while(rx_window.end() != rx_window.find(vr_r)) { // Handle any SDU segments for(uint32_t i=0; imsg[rx_sdu->N_bytes], rx_window[vr_r].buf->msg, len); - rx_sdu->N_bytes += len; - rx_window[vr_r].buf->msg += len; - rx_window[vr_r].buf->N_bytes -= len; - log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU", rrc->get_rb_name(lcid).c_str()); - rx_sdu->set_timestamp(); - pdcp->write_pdu(lcid, rx_sdu); - rx_sdu = pool_allocate; - if (!rx_sdu) { + uint32_t len = rx_window[vr_r].header.li[i]; + if (rx_sdu->get_tailroom() >= len) { + memcpy(&rx_sdu->msg[rx_sdu->N_bytes], rx_window[vr_r].buf->msg, len); + rx_sdu->N_bytes += len; + rx_window[vr_r].buf->msg += len; + rx_window[vr_r].buf->N_bytes -= len; + log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU (%d B)", rrc->get_rb_name(lcid).c_str(), rx_sdu->N_bytes); + rx_sdu->set_timestamp(); + pdcp->write_pdu(lcid, rx_sdu); + + rx_sdu = pool_allocate; + if (!rx_sdu) { #ifdef RLC_AM_BUFFER_DEBUG - log->console("Fatal Error: Could not allocate PDU in reassemble_rx_sdus() (2)\n"); - exit(-1); + log->console("Fatal Error: Could not allocate PDU in reassemble_rx_sdus() (2)\n"); + exit(-1); #else - log->error("Fatal Error: Could not allocate PDU in reassemble_rx_sdus() (2)\n"); - return; + log->error("Fatal Error: Could not allocate PDU in reassemble_rx_sdus() (2)\n"); + return; #endif + } + } else { + log->error("Cannot fit RLC PDU in SDU buffer, dropping both.\n"); + pool->deallocate(rx_sdu); + pool->deallocate(rx_window[vr_r].buf); + rx_window.erase(vr_r); } } // Handle last segment - memcpy(&rx_sdu->msg[rx_sdu->N_bytes], rx_window[vr_r].buf->msg, rx_window[vr_r].buf->N_bytes); - rx_sdu->N_bytes += rx_window[vr_r].buf->N_bytes; - if(rlc_am_end_aligned(rx_window[vr_r].header.fi)) - { - log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU", rrc->get_rb_name(lcid).c_str()); + uint32_t len = rx_window[vr_r].buf->N_bytes; + if (rx_sdu->get_tailroom() >= len) { + memcpy(&rx_sdu->msg[rx_sdu->N_bytes], rx_window[vr_r].buf->msg, len); + rx_sdu->N_bytes += rx_window[vr_r].buf->N_bytes; + } else { + log->error("Cannot fit RLC PDU in SDU buffer, dropping both.\n"); + pool->deallocate(rx_sdu); + pool->deallocate(rx_window[vr_r].buf); + rx_window.erase(vr_r); + } + + if(rlc_am_end_aligned(rx_window[vr_r].header.fi)) { + log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU (%d B)", rrc->get_rb_name(lcid).c_str(), rx_sdu->N_bytes); rx_sdu->set_timestamp(); pdcp->write_pdu(lcid, rx_sdu); rx_sdu = pool_allocate; @@ -1250,7 +1273,7 @@ void rlc_am::print_rx_segments() for(it=rx_segments.begin();it!=rx_segments.end();it++) { std::list::iterator segit; for(segit = it->second.segments.begin(); segit != it->second.segments.end(); segit++) { - ss << " SN:" << segit->header.sn << " SO:" << segit->header.so << " N:" << segit->buf->N_bytes << std::endl; + ss << " SN:" << segit->header.sn << " SO:" << segit->header.so << " N:" << segit->buf->N_bytes << " N_li: " << segit->header.N_li << std::endl; } } log->debug("%s\n", ss.str().c_str()); From 6184a8b6aad619884b1f39d3182fcfd1d8ac5ce5 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 28 Mar 2018 18:17:34 +0100 Subject: [PATCH 121/143] Fixed bug in GUTI allocation for multiple UEs. --- srsepc/src/mme/s1ap.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 3fe34806c..4b1bbd688 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -78,7 +78,7 @@ s1ap::init(s1ap_args_t s1ap_args, srslte::log_filter *s1ap_log, hss_interface_s1 m_s1ap_args = s1ap_args; srslte::s1ap_mccmnc_to_plmn(s1ap_args.mcc, s1ap_args.mnc, &m_plmn); - m_next_m_tmsi = 0xF000; + m_next_m_tmsi = rand(); //Init log m_s1ap_log = s1ap_log; @@ -542,8 +542,8 @@ s1ap::activate_eps_bearer(uint64_t imsi, uint8_t ebi) uint32_t s1ap::allocate_m_tmsi(uint64_t imsi) { - // uint32_t m_tmsi = m_next_m_tmsi++; - uint32_t m_tmsi = m_next_m_tmsi; + uint32_t m_tmsi = m_next_m_tmsi++; + //uint32_t m_tmsi = m_next_m_tmsi; m_tmsi_to_imsi.insert(std::pair(m_tmsi,imsi)); m_s1ap_log->debug("Allocated M-TMSI 0x%x to IMSI %015lu,\n",m_tmsi,imsi); return m_tmsi; From 08212a6b1344ea4e22641490a8fb755f0d0e8e06 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 29 Mar 2018 10:27:19 +0200 Subject: [PATCH 122/143] fix compile warning due to missing async thread --- lib/src/phy/rf/rf_uhd_imp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/src/phy/rf/rf_uhd_imp.c b/lib/src/phy/rf/rf_uhd_imp.c index b4b0cfcd6..1c09b7990 100644 --- a/lib/src/phy/rf/rf_uhd_imp.c +++ b/lib/src/phy/rf/rf_uhd_imp.c @@ -35,6 +35,8 @@ #include "srslte/phy/rf/rf.h" #include "uhd_c_api.h" +#define HAVE_ASYNC_THREAD 0 + typedef struct { char *devname; uhd_usrp_handle usrp; @@ -87,6 +89,7 @@ static void log_late(rf_uhd_handler_t *h, bool is_rx) { } } +#if HAVE_ASYNC_THREAD static void log_underflow(rf_uhd_handler_t *h) { if (h->uhd_error_handler) { srslte_rf_error_t error; @@ -95,6 +98,7 @@ static void log_underflow(rf_uhd_handler_t *h) { h->uhd_error_handler(error); } } +#endif static void log_rx_error(rf_uhd_handler_t *h) { if (h->uhd_error_handler) { @@ -109,6 +113,7 @@ static void log_rx_error(rf_uhd_handler_t *h) { } } +#if HAVE_ASYNC_THREAD static void* async_thread(void *h) { rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h; uhd_async_metadata_handle md; @@ -135,6 +140,7 @@ static void* async_thread(void *h) { uhd_async_metadata_free(&md); return NULL; } +#endif void rf_uhd_suppress_stdout(void *h) { rf_uhd_register_msg_handler_c(suppress_handler); @@ -570,13 +576,14 @@ int rf_uhd_open_multi(char *args, void **h, uint32_t nof_channels) rf_uhd_set_rx_gain(handler, max_gain*0.7); uhd_meta_range_free(&gain_range); +#if HAVE_ASYNC_THREAD // Start low priority thread to receive async commands - /* handler->async_thread_running = true; if (pthread_create(&handler->async_thread, NULL, async_thread, handler)) { perror("pthread_create"); return -1; - }*/ + } +#endif /* Restore priorities */ uhd_set_thread_priority(0, false); From ded550b793053896262e170cae02f6e1bb95f77d Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 29 Mar 2018 10:28:36 +0200 Subject: [PATCH 123/143] remove unneeded boost includes --- srsenb/src/enb.cc | 1 - srsepc/hdr/mme/mme_gtpc.h | 1 - srsepc/src/hss/hss.cc | 1 - srsepc/src/spgw/spgw.cc | 1 - 4 files changed, 4 deletions(-) diff --git a/srsenb/src/enb.cc b/srsenb/src/enb.cc index 6e5e06669..df9ea9a45 100644 --- a/srsenb/src/enb.cc +++ b/srsenb/src/enb.cc @@ -25,7 +25,6 @@ */ #include -#include #include #include "enb.h" diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index 23e6acf0a..f41172cce 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -29,7 +29,6 @@ #include "srslte/common/log.h" #include "srslte/common/log_filter.h" #include "srslte/common/buffer_pool.h" -#include #include "srslte/asn1/gtpc.h" #include "mme/s1ap_common.h" namespace srsepc diff --git a/srsepc/src/hss/hss.cc b/srsepc/src/hss/hss.cc index a3bc797b4..703928270 100644 --- a/srsepc/src/hss/hss.cc +++ b/srsepc/src/hss/hss.cc @@ -28,7 +28,6 @@ #include #include #include -#include #include "hss/hss.h" #include "srslte/common/security.h" diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index 191e131df..1ef33a8f0 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -26,7 +26,6 @@ #include #include -#include #include #include #include From 9c006e45859f13cf1e9fe62076035393ca462894 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 29 Mar 2018 12:12:15 +0200 Subject: [PATCH 124/143] remove boost system dependency --- CMakeLists.txt | 1 - README.md | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98023d7b5..1fde57f27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,7 +171,6 @@ if(ENABLE_SRSUE OR ENABLE_SRSENB OR ENABLE_SRSEPC) set(BOOST_REQUIRED_COMPONENTS program_options - system ) if(UNIX AND EXISTS "/usr/lib64") list(APPEND BOOST_LIBRARYDIR "/usr/lib64") #fedora 64-bit fix diff --git a/README.md b/README.md index 1567c7c71..a8f186a62 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ Build Instructions For example, on Ubuntu 17.04, one can install the required libraries with: ``` -sudo apt-get install cmake libfftw3-dev libmbedtls-dev libboost-program-options-dev libboost-thread-dev libconfig++-dev libsctp-dev +sudo apt-get install cmake libfftw3-dev libmbedtls-dev libboost-program-options-dev libconfig++-dev libsctp-dev ``` Note that depending on your flavor and version of Linux, the actual package names may be different. From 5f9e0adbb6986b7a6e80ffd6550a14b762144151 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 29 Mar 2018 11:47:01 +0100 Subject: [PATCH 125/143] Making sure cmath is included for std::pow --- srsepc/src/mme/s1ap_nas_transport.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index eb64a09eb..f64e4ff0d 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -25,6 +25,7 @@ */ #include +#include #include "mme/s1ap.h" #include "mme/s1ap_nas_transport.h" #include "srslte/common/security.h" From 308efd4fdc74ff23487773955c256111e3f33efd Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 29 Mar 2018 12:02:16 +0100 Subject: [PATCH 126/143] Avoid overflow on M-TMSI allocation. --- srsepc/src/mme/s1ap.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 4b1bbd688..0dce45c41 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -542,8 +542,9 @@ s1ap::activate_eps_bearer(uint64_t imsi, uint8_t ebi) uint32_t s1ap::allocate_m_tmsi(uint64_t imsi) { - uint32_t m_tmsi = m_next_m_tmsi++; - //uint32_t m_tmsi = m_next_m_tmsi; + uint32_t m_tmsi = m_next_m_tmsi; + m_next_m_tmsi = (m_next_m_tmsi + 1) % UINT32_MAX; + m_tmsi_to_imsi.insert(std::pair(m_tmsi,imsi)); m_s1ap_log->debug("Allocated M-TMSI 0x%x to IMSI %015lu,\n",m_tmsi,imsi); return m_tmsi; From 3db9ddcd3664450a1623d207d089ddedfac5f306 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 29 Mar 2018 13:44:42 +0200 Subject: [PATCH 127/143] remove various debug prints --- lib/src/common/pdu.cc | 1 - srsue/src/main.cc | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/src/common/pdu.cc b/lib/src/common/pdu.cc index 80db7627d..95d9dde9b 100644 --- a/lib/src/common/pdu.cc +++ b/lib/src/common/pdu.cc @@ -124,7 +124,6 @@ uint8_t* sch_pdu::write_packet(srslte::log *log_h) if (nof_subheaders <= 0 && nof_subheaders < (int)max_subheaders) { log_h->error("Trying to write packet with invalid number of subheaders (nof_subheaders=%d).\n", nof_subheaders); - log_h->console("Trying to write packet with invalid number of subheaders (nof_subheaders=%d).\n", nof_subheaders); return NULL; } diff --git a/srsue/src/main.cc b/srsue/src/main.cc index 8753e7630..30a3e3b00 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -484,8 +484,7 @@ int main(int argc, char *argv[]) plot_started = true; } } - ue->print_pool(); - sleep(10); + sleep(1); } pthread_cancel(input); metricshub.stop(); From 2cf5acf9c891537b7167208b86b1caa918db229f Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 29 Mar 2018 14:48:35 +0200 Subject: [PATCH 128/143] set valgrind options correctly this avoid an ugly valgrind error after executing long sequences of simd code see: https://www.bountysource.com/issues/41603953-temporary-storage-exhausted-when-long-sequence-of-vfmadd231ps-instructions-to-be-executed --- CMakeLists.txt | 2 -- CTestConfig.cmake | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fde57f27..52716499e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,8 +41,6 @@ include(SRSLTEVersion) #sets version information include(SRSLTEPackage) #setup cpack include(CTest) -set(CTEST_MEMORYCHECK_COMMAND valgrind) -set(CTEST_MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full" ) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in" diff --git a/CTestConfig.cmake b/CTestConfig.cmake index 1c4aa5735..d8e316006 100644 --- a/CTestConfig.cmake +++ b/CTestConfig.cmake @@ -11,3 +11,4 @@ set(CTEST_DROP_METHOD "http") set(CTEST_DROP_SITE "my.cdash.org") set(CTEST_DROP_LOCATION "/submit.php?project=srsLTE") set(CTEST_DROP_SITE_CDASH TRUE) +set(VALGRIND_COMMAND_OPTIONS "--trace-children=yes --leak-check=full --show-reachable=yes --vex-guest-max-insns=25") \ No newline at end of file From 9b689d479fc7feaee47380ee938060095bf01926 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 29 Mar 2018 16:47:10 +0200 Subject: [PATCH 129/143] bumping version number to 18.03 --- cmake/modules/SRSLTEVersion.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/modules/SRSLTEVersion.cmake b/cmake/modules/SRSLTEVersion.cmake index fec6ab21f..30d2707b0 100644 --- a/cmake/modules/SRSLTEVersion.cmake +++ b/cmake/modules/SRSLTEVersion.cmake @@ -18,7 +18,7 @@ # and at http://www.gnu.org/licenses/. # -SET(SRSLTE_VERSION_MAJOR 17) -SET(SRSLTE_VERSION_MINOR 12) +SET(SRSLTE_VERSION_MAJOR 18) +SET(SRSLTE_VERSION_MINOR 3) SET(SRSLTE_VERSION_PATCH 0) SET(SRSLTE_VERSION_STRING "${SRSLTE_VERSION_MAJOR}.${SRSLTE_VERSION_MINOR}.${SRSLTE_VERSION_PATCH}") From 49da57c8a14b59e227ea5ff533dd34d0c3538882 Mon Sep 17 00:00:00 2001 From: Joseph Giovatto Date: Mon, 19 Feb 2018 22:03:07 -0500 Subject: [PATCH 130/143] Changed log methods to take string literal vs string object to allow for format checking and save on object copy. Fixed log format specifier warnings. --- CMakeLists.txt | 2 +- lib/include/srslte/common/log.h | 10 +++++----- lib/include/srslte/common/log_filter.h | 10 +++++----- lib/src/common/log_filter.cc | 20 ++++++++++---------- lib/src/upper/rlc_am.cc | 4 ++-- srsenb/src/enb.cc | 2 +- srsenb/src/phy/phch_worker.cc | 4 ++-- srsenb/src/phy/txrx.cc | 2 +- srsenb/src/upper/rrc.cc | 8 ++++---- srsepc/src/mme/s1ap_nas_transport.cc | 8 ++++---- srsue/src/mac/proc_phr.cc | 4 ++-- srsue/src/phy/phch_recv.cc | 6 +++--- srsue/src/phy/prach.cc | 2 +- srsue/src/ue_base.cc | 2 +- srsue/src/upper/nas.cc | 2 +- srsue/src/upper/rrc.cc | 6 +++--- srsue/src/upper/usim.cc | 16 ++++++++-------- 17 files changed, 54 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 52716499e..290754ee3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,7 +226,7 @@ macro(ADD_CXX_COMPILER_FLAG_IF_AVAILABLE flag have) endmacro(ADD_CXX_COMPILER_FLAG_IF_AVAILABLE) if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${GCC_ARCH} -Wall -Wno-comment -Wno-reorder -Wno-unused-but-set-variable -Wno-unused-variable -std=c++03") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${GCC_ARCH} -Wall -Wno-comment -Wno-reorder -Wno-unused-but-set-variable -Wno-unused-variable -Wformat -std=c++03") find_package(SSE) if (HAVE_AVX2) diff --git a/lib/include/srslte/common/log.h b/lib/include/srslte/common/log.h index 360482c47..45c359629 100644 --- a/lib/include/srslte/common/log.h +++ b/lib/include/srslte/common/log.h @@ -122,11 +122,11 @@ public: } // Pure virtual methods for logging - virtual void console(std::string message, ...) = 0; - virtual void error(std::string message, ...) = 0; - virtual void warning(std::string message, ...) = 0; - virtual void info(std::string message, ...) = 0; - virtual void debug(std::string message, ...) = 0; + virtual void console(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; + virtual void error(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; + virtual void warning(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; + virtual void info(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; + virtual void debug(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; // Same with hex dump virtual void error_hex(uint8_t *hex, int size, std::string message, ...){error("error_hex not implemented.\n");} diff --git a/lib/include/srslte/common/log_filter.h b/lib/include/srslte/common/log_filter.h index 7e4014190..430a59199 100644 --- a/lib/include/srslte/common/log_filter.h +++ b/lib/include/srslte/common/log_filter.h @@ -57,11 +57,11 @@ public: void init(std::string layer, logger *logger_, bool tti=false); - void console(std::string message, ...); - void error(std::string message, ...); - void warning(std::string message, ...); - void info(std::string message, ...); - void debug(std::string message, ...); + void console(const char * message, ...); + void error(const char * message, ...); + void warning(const char * message, ...); + void info(const char * message, ...); + void debug(const char * message, ...); void error_hex(uint8_t *hex, int size, std::string message, ...); void warning_hex(uint8_t *hex, int size, std::string message, ...); diff --git a/lib/src/common/log_filter.cc b/lib/src/common/log_filter.cc index 8b72a3c2b..b79e222e7 100644 --- a/lib/src/common/log_filter.cc +++ b/lib/src/common/log_filter.cc @@ -135,55 +135,55 @@ void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, } } -void log_filter::console(std::string message, ...) { +void log_filter::console(const char * message, ...) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) printf("%s",args_msg); // Print directly to stdout va_end(args); free(args_msg); } -void log_filter::error(std::string message, ...) { +void log_filter::error(const char * message, ...) { if (level >= LOG_LEVEL_ERROR) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_ERROR, tti, args_msg); va_end(args); free(args_msg); } } -void log_filter::warning(std::string message, ...) { +void log_filter::warning(const char * message, ...) { if (level >= LOG_LEVEL_WARNING) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_WARNING, tti, args_msg); va_end(args); free(args_msg); } } -void log_filter::info(std::string message, ...) { +void log_filter::info(const char * message, ...) { if (level >= LOG_LEVEL_INFO) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_INFO, tti, args_msg); va_end(args); free(args_msg); } } -void log_filter::debug(std::string message, ...) { +void log_filter::debug(const char * message, ...) { if (level >= LOG_LEVEL_DEBUG) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_DEBUG, tti, args_msg); va_end(args); free(args_msg); diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index d100508d1..2537ee48c 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -342,7 +342,7 @@ int rlc_am::read_pdu(uint8_t *payload, uint32_t nof_bytes) pthread_mutex_lock(&mutex); log->debug("MAC opportunity - %d bytes\n", nof_bytes); - log->debug("tx_window size - %d PDUs\n", tx_window.size()); + log->debug("tx_window size - %zu PDUs\n", tx_window.size()); // Tx STATUS if requested if(do_status && !status_prohibited()) { @@ -698,7 +698,7 @@ int rlc_am::build_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_retx_t r if(pdu_len > (int)nof_bytes) { log->error("%s Retx PDU segment length error. Available: %d, Used: %d\n", rrc->get_rb_name(lcid).c_str(), nof_bytes, pdu_len); - log->debug("%s Retx PDU segment length error. Header len: %d, Payload len: %d, N_li: %d\n", + log->debug("%s Retx PDU segment length error. Header len: %ld, Payload len: %d, N_li: %d\n", rrc->get_rb_name(lcid).c_str(), (ptr-payload), len, new_header.N_li); } return pdu_len; diff --git a/srsenb/src/enb.cc b/srsenb/src/enb.cc index df9ea9a45..2d3466522 100644 --- a/srsenb/src/enb.cc +++ b/srsenb/src/enb.cc @@ -297,7 +297,7 @@ void enb::handle_rf_msg(srslte_rf_error_t error) str.erase(std::remove(str.begin(), str.end(), '\n'), str.end()); str.erase(std::remove(str.begin(), str.end(), '\r'), str.end()); str.push_back('\n'); - rf_log.info(str); + rf_log.info(str.c_str()); } } diff --git a/srsenb/src/phy/phch_worker.cc b/srsenb/src/phy/phch_worker.cc index 8013a7d5c..5524be442 100644 --- a/srsenb/src/phy/phch_worker.cc +++ b/srsenb/src/phy/phch_worker.cc @@ -227,7 +227,7 @@ void phch_worker::set_conf_dedicated_ack(uint16_t rnti, bool ack){ if (ue_db.count(rnti)) { ue_db[rnti].dedicated_ack = ack; } else { - Error("Setting dedicated ack: rnti=0x%x does not exist\n"); + Error("Setting dedicated ack: rnti=0x%x does not exist\n", rnti); } pthread_mutex_unlock(&mutex); } @@ -309,7 +309,7 @@ void phch_worker::set_config_dedicated(uint16_t rnti, ue_db[rnti].dedicated.pdsch_cnfg_ded = dedicated->pdsch_cnfg_ded; } } else { - Error("Setting config dedicated: rnti=0x%x does not exist\n"); + Error("Setting config dedicated: rnti=0x%x does not exist\n", rnti); } pthread_mutex_unlock(&mutex); } diff --git a/srsenb/src/phy/txrx.cc b/srsenb/src/phy/txrx.cc index fbc96ea72..32c8aea00 100644 --- a/srsenb/src/phy/txrx.cc +++ b/srsenb/src/phy/txrx.cc @@ -125,7 +125,7 @@ void txrx::run_thread() srslte_timestamp_copy(&tx_time, &rx_time); srslte_timestamp_add(&tx_time, 0, HARQ_DELAY_MS*1e-3); - Debug("Settting TTI=%d, tx_mutex=%d, tx_time=%d:%f to worker %d\n", + Debug("Settting TTI=%d, tx_mutex=%d, tx_time=%ld:%f to worker %d\n", tti, tx_mutex_cnt, tx_time.full_secs, tx_time.frac_secs, worker->get_id()); diff --git a/srsenb/src/upper/rrc.cc b/srsenb/src/upper/rrc.cc index e025dfca4..9fe1773f7 100644 --- a/srsenb/src/upper/rrc.cc +++ b/srsenb/src/upper/rrc.cc @@ -225,7 +225,7 @@ void rrc::add_user(uint16_t rnti) pdcp->add_user(rnti); rrc_log->info("Added new user rnti=0x%x\n", rnti); } else { - rrc_log->error("Adding user rnti=0x%x (already exists)\n"); + rrc_log->error("Adding user rnti=0x%x (already exists)\n", rnti); } pthread_mutex_unlock(&user_mutex); } @@ -584,7 +584,7 @@ void rrc::parse_ul_ccch(uint16_t rnti, byte_buffer_t *pdu) if (users[rnti].is_idle()) { old_rnti = ul_ccch_msg.msg.rrc_con_reest_req.ue_id.c_rnti; if (users.count(old_rnti)) { - rrc_log->error("Not supported: ConnectionReestablishment. Sending Connection Reject\n", old_rnti); + rrc_log->error("Not supported: ConnectionReestablishment for rnti=0x%x. Sending Connection Reject\n", old_rnti); users[rnti].send_connection_reest_rej(); rem_user_thread(old_rnti); } else { @@ -649,7 +649,7 @@ void rrc::run_thread() pthread_mutex_lock(&user_mutex); break; default: - rrc_log->error("Rx PDU with invalid bearer id: %s", p.lcid); + rrc_log->error("Rx PDU with invalid bearer id: %d", p.lcid); break; } } else { @@ -799,7 +799,7 @@ bool rrc::ue::is_timeout() int64_t deadline = deadline_s*1e6 + deadline_us; int64_t elapsed = t[0].tv_sec*1e6 + t[0].tv_usec; if (elapsed > deadline && elapsed > 0) { - parent->rrc_log->warning("User rnti=0x%x expired %s deadline: %d:%d>%d:%d us\n", + parent->rrc_log->warning("User rnti=0x%x expired %s deadline: %ld:%ld>%d:%d us\n", rnti, deadline_str, t[0].tv_sec, t[0].tv_usec, deadline_s, deadline_us); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index f64e4ff0d..5d6922554 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -1128,13 +1128,13 @@ s1ap_nas_transport::handle_esm_information_response(srslte::byte_buffer_t *nas_m m_s1ap_log->info("ESM Info: EPS bearer id %d\n",esm_info_resp.eps_bearer_id); if(esm_info_resp.apn_present) { - m_s1ap_log->info("ESM Info: APN %s\n",esm_info_resp.eps_bearer_id); - m_s1ap_log->console("ESM Info: APN %s\n",esm_info_resp.eps_bearer_id); + m_s1ap_log->info("ESM Info: APN %d\n",esm_info_resp.eps_bearer_id); + m_s1ap_log->console("ESM Info: APN %d\n",esm_info_resp.eps_bearer_id); } if(esm_info_resp.protocol_cnfg_opts_present) { - m_s1ap_log->info("ESM Info: %d Protocol Configuration Options %s\n",esm_info_resp.protocol_cnfg_opts.N_opts); - m_s1ap_log->console("ESM Info: %d Protocol Configuration Options %s\n",esm_info_resp.protocol_cnfg_opts.N_opts); + m_s1ap_log->info("ESM Info: %d Protocol Configuration Options\n",esm_info_resp.protocol_cnfg_opts.N_opts); + m_s1ap_log->console("ESM Info: %d Protocol Configuration Options\n",esm_info_resp.protocol_cnfg_opts.N_opts); } //FIXME The packging of GTP-C messages is not ready. diff --git a/srsue/src/mac/proc_phr.cc b/srsue/src/mac/proc_phr.cc index 54c1ec1ce..3eb7c82f5 100644 --- a/srsue/src/mac/proc_phr.cc +++ b/srsue/src/mac/proc_phr.cc @@ -91,7 +91,7 @@ void phr_proc::timer_expired(uint32_t timer_id) { } else if (timer_id == timer_prohibit_id) { int pathloss_db = liblte_rrc_dl_pathloss_change_num[mac_cfg->main.phr_cnfg.dl_pathloss_change]; if (pathloss_changed()) { - Info("PHR: Triggered by pathloss difference. cur_pathloss_db=%f (timer expired)\n", last_pathloss_db); + Info("PHR: Triggered by pathloss difference. cur_pathloss_db=%d (timer expired)\n", last_pathloss_db); phr_is_triggered = true; } } else { @@ -132,7 +132,7 @@ void phr_proc::step(uint32_t tti) } if (pathloss_changed() && timers_db->get(timer_prohibit_id)->is_expired()) { - Info("PHR: Triggered by pathloss difference. cur_pathloss_db=%f\n", last_pathloss_db); + Info("PHR: Triggered by pathloss difference. cur_pathloss_db=%d\n", last_pathloss_db); phr_is_triggered = true; } } diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index 0df792fd5..ab550aaa2 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -275,7 +275,7 @@ void phch_recv::cell_search_inc() phy_state = IDLE; rrc->earfcn_end(); } else { - Info("SYNC: Cell Search idx %d/%d\n", cur_earfcn_index, earfcn.size()); + Info("SYNC: Cell Search idx %d/%zu\n", cur_earfcn_index, earfcn.size()); if (current_earfcn != earfcn[cur_earfcn_index]) { current_earfcn = earfcn[cur_earfcn_index]; set_frequency(); @@ -297,7 +297,7 @@ void phch_recv::cell_search_start() { Warning("SYNC: Can't start cell search procedure while camping on cell\n"); } else { if (earfcn.size() > 0) { - Info("SYNC: Starting Cell Search procedure in %d EARFCNs...\n", earfcn.size()); + Info("SYNC: Starting Cell Search procedure in %zu EARFCNs...\n", earfcn.size()); cell_search_next(true); } else { Info("SYNC: Empty EARFCN list. Stopping cell search...\n"); @@ -1502,7 +1502,7 @@ void phch_recv::intra_measure::rem_cell(int pci) { if (active_pci.size() == 0) { receive_enabled = false; } - Info("INTRA: Stopping intra-frequency measurement for pci=%d. Number of cells: %d\n", pci, active_pci.size()); + Info("INTRA: Stopping intra-frequency measurement for pci=%d. Number of cells: %zu\n", pci, active_pci.size()); } else { Warning("INTRA: Requested to stop non-existing intra-frequency measurement for PCI=%d\n", pci); } diff --git a/srsue/src/phy/prach.cc b/srsue/src/phy/prach.cc index fdf925642..a1bf96c85 100644 --- a/srsue/src/phy/prach.cc +++ b/srsue/src/phy/prach.cc @@ -201,7 +201,7 @@ void prach::send(srslte::radio *radio_handler, float cfo, float pathloss, srslte float scale = sqrtf(pow(10,tx_power/10)/digital_power); srslte_vec_sc_prod_cfc(signal_buffer, scale, signal_buffer, len); - log_h->console("PRACH: Pathloss=%.2f dB, Target power %.2f dBm, TX_power %.2f dBm, TX_gain %.1f dB\n", + log_h->console("PRACH: Pathloss=%.2f dB, Target power %.2f dBm, TX_power %.2f dBm, TX_gain %.1f dB, scale %.2f\n", pathloss, target_power_dbm, tx_power, radio_handler->get_tx_gain(), scale); } else { diff --git a/srsue/src/ue_base.cc b/srsue/src/ue_base.cc index a4264a099..71430fc9f 100644 --- a/srsue/src/ue_base.cc +++ b/srsue/src/ue_base.cc @@ -104,7 +104,7 @@ void ue_base::handle_rf_msg(srslte_rf_error_t error) str.erase(std::remove(str.begin(), str.end(), '\n'), str.end()); str.erase(std::remove(str.begin(), str.end(), '\r'), str.end()); str.push_back('\n'); - rf_log.info(str); + rf_log.info(str.c_str()); } } diff --git a/srsue/src/upper/nas.cc b/srsue/src/upper/nas.cc index 939db1686..5b7f40920 100644 --- a/srsue/src/upper/nas.cc +++ b/srsue/src/upper/nas.cc @@ -682,7 +682,7 @@ void nas::parse_identity_request(uint32_t lcid, byte_buffer_t *pdu) { usim->get_imei_vec(id_resp.mobile_id.imei, 15); break; default: - nas_log->error("Unhandled ID type: %d\n"); + nas_log->error("Unhandled ID type: %d\n", id_req.id_type); pool->deallocate(pdu); return; } diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index e419ea710..4dde6361d 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -1680,7 +1680,7 @@ void rrc::write_pdu(uint32_t lcid, byte_buffer_t *pdu) { parse_dl_dcch(lcid, pdu); break; default: - rrc_log->error("RX PDU with invalid bearer id: %s", lcid); + rrc_log->error("RX PDU with invalid bearer id: %d", lcid); break; } } @@ -2891,8 +2891,8 @@ void rrc::rrc_meas::parse_meas_config(LIBLTE_RRC_MEAS_CONFIG_STRUCT *cfg) log_h->info("MEAS: Added measObjectId=%d, earfcn=%d, q_offset=%f, pci=%d, offset_cell=%f\n", cfg->meas_obj_to_add_mod_list.meas_obj_list[i].meas_obj_id, dst_obj->earfcn, dst_obj->q_offset, - dst_obj->cells[src_obj->cells_to_add_mod_list[j].cell_idx].q_offset, - dst_obj->cells[src_obj->cells_to_add_mod_list[j].cell_idx].pci); + dst_obj->cells[src_obj->cells_to_add_mod_list[j].cell_idx].pci, + dst_obj->cells[src_obj->cells_to_add_mod_list[j].cell_idx].q_offset); } diff --git a/srsue/src/upper/usim.cc b/srsue/src/upper/usim.cc index b9f4fda0e..d344734ba 100644 --- a/srsue/src/upper/usim.cc +++ b/srsue/src/upper/usim.cc @@ -49,8 +49,8 @@ void usim::init(usim_args_t *args, srslte::log *usim_log_) if(32 == args->op.length()) { str_to_hex(args->op, op); } else { - usim_log->error("Invalid length for OP: %d should be %d", args->op.length(), 32); - usim_log->console("Invalid length for OP: %d should be %d", args->op.length(), 32); + usim_log->error("Invalid length for OP: %zu should be %d", args->op.length(), 32); + usim_log->console("Invalid length for OP: %zu should be %d", args->op.length(), 32); } if(15 == args->imsi.length()) { @@ -61,8 +61,8 @@ void usim::init(usim_args_t *args, srslte::log *usim_log_) imsi += imsi_c[i] - '0'; } } else { - usim_log->error("Invalid length for ISMI: %d should be %d", args->imsi.length(), 15); - usim_log->console("Invalid length for IMSI: %d should be %d", args->imsi.length(), 15); + usim_log->error("Invalid length for ISMI: %zu should be %d", args->imsi.length(), 15); + usim_log->console("Invalid length for IMSI: %zu should be %d", args->imsi.length(), 15); } if(15 == args->imei.length()) { @@ -73,15 +73,15 @@ void usim::init(usim_args_t *args, srslte::log *usim_log_) imei += imei_c[i] - '0'; } } else { - usim_log->error("Invalid length for IMEI: %d should be %d", args->imei.length(), 15); - usim_log->console("Invalid length for IMEI: %d should be %d", args->imei.length(), 15); + usim_log->error("Invalid length for IMEI: %zu should be %d", args->imei.length(), 15); + usim_log->console("Invalid length for IMEI: %zu should be %d", args->imei.length(), 15); } if(32 == args->k.length()) { str_to_hex(args->k, k); } else { - usim_log->error("Invalid length for K: %d should be %d", args->k.length(), 32); - usim_log->console("Invalid length for K: %d should be %d", args->k.length(), 32); + usim_log->error("Invalid length for K: %zu should be %d", args->k.length(), 32); + usim_log->console("Invalid length for K: %zu should be %d", args->k.length(), 32); } auth_algo = auth_algo_milenage; From ff85e8b77ff8c281429c1f52bdccf663a4071b05 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 29 Mar 2018 17:23:55 +0200 Subject: [PATCH 131/143] fixing remaining printf formating issues --- srsepc/src/mme/s1ap_nas_transport.cc | 9 +++++---- srsue/src/phy/phch_recv.cc | 2 +- srsue/src/upper/rrc.cc | 11 ++++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 5d6922554..183815fc6 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -26,6 +26,7 @@ #include #include +#include // for printing uint64_t #include "mme/s1ap.h" #include "mme/s1ap_nas_transport.h" #include "srslte/common/security.h" @@ -185,11 +186,11 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA ue_ctx_t *ue_ctx = m_s1ap->find_ue_ctx_from_mme_ue_s1ap_id(mme_ue_s1ap_id); if(ue_ctx == NULL) { - m_s1ap_log->warning("Received uplink NAS, but could not find UE ECM context. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); + m_s1ap_log->warning("Received uplink NAS, but could not find UE ECM context. MME-UE S1AP id: %d\n",mme_ue_s1ap_id); return false; } - m_s1ap_log->debug("Received uplink NAS and found UE ECM context. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); + m_s1ap_log->debug("Received uplink NAS and found UE ECM context. MME-UE S1AP id: %d\n",mme_ue_s1ap_id); ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; @@ -213,7 +214,7 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA //This can happen with integrity protected identity reponse messages if( !(msg_type == LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE && sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY)) { - m_s1ap_log->warning("Uplink NAS: could not find security context for integrity protected message. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); + m_s1ap_log->warning("Uplink NAS: could not find security context for integrity protected message. MME-UE S1AP id: %d\n",mme_ue_s1ap_id); m_pool->deallocate(nas_msg); return false; } @@ -1092,7 +1093,7 @@ s1ap_nas_transport::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, u ue_emm_ctx_t *emm_ctx = &ue_ctx->emm_ctx; ue_ecm_ctx_t *ecm_ctx = &ue_ctx->ecm_ctx; - m_s1ap_log->console("Unpacked Attached Complete Message. IMSI %d\n", emm_ctx->imsi); + m_s1ap_log->console("Unpacked Attached Complete Message. IMSI %" PRIu64 "\n", emm_ctx->imsi); m_s1ap_log->console("Unpacked Activate Default EPS Bearer message. EPS Bearer id %d\n",act_bearer.eps_bearer_id); //ue_ctx->erabs_ctx[act_bearer->eps_bearer_id].enb_fteid; if(act_bearer.eps_bearer_id < 5 || act_bearer.eps_bearer_id > 15) diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index ab550aaa2..49b0af307 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -1198,7 +1198,7 @@ phch_recv::measure::ret_code phch_recv::measure::run_subframe(uint32_t sf_idx) } cnt++; - log_h->debug("SYNC: Measuring RSRP %d/%d, sf_idx=%d, RSRP=%.1f dBm, corr-RSRP=%.1f dBm, SNR=%.1f dB\n", + log_h->debug("SYNC: Measuring RSRP %d/%d, sf_idx=%d, RSRP=%.1f dBm, SNR=%.1f dB\n", cnt, nof_subframes, sf_idx, rsrp, snr); if (cnt >= nof_subframes) { diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index 4dde6361d..53e85fac8 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -30,6 +30,7 @@ #include #include #include +#include // for printing uint64_t #include #include "upper/rrc.h" #include "srslte/asn1/liblte_rrc.h" @@ -528,7 +529,7 @@ void rrc::set_serving_cell(uint32_t cell_idx) { // Set new serving cell serving_cell = new_serving_cell; - rrc_log->info("Setting serving cell idx=%d, earfcn=%d, PCI=%d, nof_neighbours=%d\n", + rrc_log->info("Setting serving cell idx=%d, earfcn=%d, PCI=%d, nof_neighbours=%zd\n", cell_idx, serving_cell->get_earfcn(), serving_cell->phy_cell.id, neighbour_cells.size()); } else { @@ -751,7 +752,7 @@ bool rrc::add_neighbour_cell(cell_t *new_cell) { if (ret) { neighbour_cells.push_back(new_cell); } - rrc_log->info("Added neighbour cell EARFCN=%d, PCI=%d, nof_neighbours=%d\n", + rrc_log->info("Added neighbour cell EARFCN=%d, PCI=%d, nof_neighbours=%zd\n", new_cell->get_earfcn(), new_cell->get_pci(), neighbour_cells.size()); sort_neighbour_cells(); return ret; @@ -1634,7 +1635,7 @@ void rrc::send_ul_ccch_msg() ue_cri_ptr[nbytes - i - 1] = pdu->msg[i]; } - rrc_log->debug("Setting UE contention resolution ID: %d\n", uecri); + rrc_log->debug("Setting UE contention resolution ID: %" PRIu64 "\n", uecri); mac->set_contention_id(uecri); rrc_log->info("Sending %s\n", liblte_rrc_ul_ccch_msg_type_text[ul_ccch_msg.msg_type]); @@ -2973,7 +2974,7 @@ void rrc::rrc_meas::parse_meas_config(LIBLTE_RRC_MEAS_CONFIG_STRUCT *cfg) remove_meas_id(cfg->meas_id_to_remove_list[i]); } - log_h->info("nof active measId=%d\n", active.size()); + log_h->info("nof active measId=%zd\n", active.size()); // Measurement identity addition/modification 5.5.2.3 if (cfg->meas_id_to_add_mod_list_present) { @@ -2992,7 +2993,7 @@ void rrc::rrc_meas::parse_meas_config(LIBLTE_RRC_MEAS_CONFIG_STRUCT *cfg) } active[measId->meas_id].object_id = measId->meas_obj_id; active[measId->meas_id].report_id = measId->rep_cnfg_id; - log_h->info("MEAS: %s measId=%d, measObjectId=%d, reportConfigId=%d, timer_id=%d, nof_values=%d\n", + log_h->info("MEAS: %s measId=%d, measObjectId=%d, reportConfigId=%d, timer_id=%d, nof_values=%zd\n", is_new?"Added":"Updated", measId->meas_id, measId->meas_obj_id, measId->rep_cnfg_id, active[measId->meas_id].periodic_timer, active[measId->meas_id].cell_values.size()); } From 2351ced98b5a67179e22527f7dcf81e50876d1fa Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 29 Mar 2018 17:30:52 +0200 Subject: [PATCH 132/143] adding very brief changelog for 18.03 --- CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 5a57af260..9bed0247c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ Change Log for Releases ============================== +## 18.03 + * Many bug-fixes and improved stability and performance in all parts + ## 17.12 * Added support for MIMO 2x2 in srsENB (i.e. TM3/TM4) * Added srsEPC, a light-weight core network implementation From 9d71bec7b6cf5f8421b4c24cb4d6ada925b91dca Mon Sep 17 00:00:00 2001 From: David Rupprecht Date: Sat, 31 Mar 2018 19:04:04 +0200 Subject: [PATCH 133/143] Unified include guards --- lib/include/srslte/asn1/gtpc.h | 6 +++--- lib/include/srslte/asn1/gtpc_ies.h | 6 +++--- lib/include/srslte/asn1/gtpc_msg.h | 6 +++--- lib/include/srslte/asn1/liblte_common.h | 6 +++--- lib/include/srslte/asn1/liblte_mme.h | 6 +++--- lib/include/srslte/asn1/liblte_rrc.h | 6 +++--- lib/include/srslte/asn1/liblte_s1ap.h | 6 +++--- lib/include/srslte/build_info.h.in | 4 ++-- lib/include/srslte/common/bcd_helpers.h | 6 +++--- lib/include/srslte/common/block_queue.h | 6 +++--- lib/include/srslte/common/buffer_pool.h | 6 +++--- lib/include/srslte/common/common.h | 8 ++++---- lib/include/srslte/common/config.h | 6 +++--- lib/include/srslte/common/interfaces_common.h | 6 +++--- lib/include/srslte/common/liblte_security.h | 6 +++--- lib/include/srslte/common/liblte_ssl.h | 6 +++--- lib/include/srslte/common/log.h | 6 +++--- lib/include/srslte/common/log_filter.h | 6 +++--- lib/include/srslte/common/logger.h | 6 +++--- lib/include/srslte/common/logger_file.h | 8 ++++---- lib/include/srslte/common/logger_stdout.h | 6 +++--- lib/include/srslte/common/mac_pcap.h | 8 ++++---- lib/include/srslte/common/metrics_hub.h | 6 +++--- lib/include/srslte/common/msg_queue.h | 8 ++++---- lib/include/srslte/common/nas_pcap.h | 8 ++++---- lib/include/srslte/common/pcap.h | 6 +++--- lib/include/srslte/common/pdu.h | 8 ++++---- lib/include/srslte/common/pdu_queue.h | 6 +++--- lib/include/srslte/common/security.h | 8 ++++---- lib/include/srslte/common/snow_3g.h | 3 +++ lib/include/srslte/common/task_dispatcher.h | 8 ++++---- lib/include/srslte/common/thread_pool.h | 6 +++--- lib/include/srslte/common/threads.h | 7 ++++--- lib/include/srslte/common/timeout.h | 8 ++++---- lib/include/srslte/common/timers.h | 6 +++--- lib/include/srslte/common/trace.h | 6 +++--- lib/include/srslte/common/tti_sync.h | 6 +++--- lib/include/srslte/common/tti_sync_cv.h | 8 ++++---- lib/include/srslte/config.h | 6 +++--- lib/include/srslte/interfaces/enb_interfaces.h | 6 +++--- lib/include/srslte/interfaces/enb_metrics_interface.h | 6 +++--- lib/include/srslte/interfaces/epc_interfaces.h | 6 +++--- lib/include/srslte/interfaces/sched_interface.h | 6 +++--- lib/include/srslte/interfaces/ue_interfaces.h | 8 ++++---- lib/include/srslte/phy/agc/agc.h | 6 +++--- lib/include/srslte/phy/ch_estimation/chest_common.h | 6 +++--- lib/include/srslte/phy/ch_estimation/chest_dl.h | 6 +++--- lib/include/srslte/phy/ch_estimation/chest_ul.h | 6 +++--- lib/include/srslte/phy/ch_estimation/refsignal_dl.h | 6 +++--- lib/include/srslte/phy/ch_estimation/refsignal_ul.h | 6 +++--- lib/include/srslte/phy/channel/ch_awgn.h | 6 +++--- lib/include/srslte/phy/common/phy_common.h | 6 +++--- lib/include/srslte/phy/common/phy_logger.h | 6 +++--- lib/include/srslte/phy/common/sequence.h | 6 +++--- lib/include/srslte/phy/common/timestamp.h | 6 +++--- lib/include/srslte/phy/dft/dft.h | 6 +++--- lib/include/srslte/phy/dft/dft_precoding.h | 6 +++--- lib/include/srslte/phy/dft/ofdm.h | 6 +++--- lib/include/srslte/phy/enb/enb_dl.h | 6 +++--- lib/include/srslte/phy/enb/enb_ul.h | 6 +++--- lib/include/srslte/phy/fec/cbsegm.h | 6 +++--- lib/include/srslte/phy/fec/convcoder.h | 6 +++--- lib/include/srslte/phy/fec/crc.h | 6 +++--- lib/include/srslte/phy/fec/rm_conv.h | 6 +++--- lib/include/srslte/phy/fec/rm_turbo.h | 6 +++--- lib/include/srslte/phy/fec/softbuffer.h | 6 +++--- lib/include/srslte/phy/fec/tc_interl.h | 6 +++--- lib/include/srslte/phy/fec/turbocoder.h | 6 +++--- lib/include/srslte/phy/fec/turbodecoder.h | 6 +++--- lib/include/srslte/phy/fec/turbodecoder_gen.h | 6 +++--- lib/include/srslte/phy/fec/turbodecoder_simd.h | 6 +++--- lib/include/srslte/phy/fec/turbodecoder_simd_inter.h | 6 +++--- lib/include/srslte/phy/fec/turbodecoder_sse.h | 6 +++--- lib/include/srslte/phy/fec/viterbi.h | 6 +++--- lib/include/srslte/phy/io/binsource.h | 6 +++--- lib/include/srslte/phy/io/filesink.h | 6 +++--- lib/include/srslte/phy/io/filesource.h | 6 +++--- lib/include/srslte/phy/io/format.h | 6 +++--- lib/include/srslte/phy/io/netsink.h | 6 +++--- lib/include/srslte/phy/io/netsource.h | 6 +++--- lib/include/srslte/phy/mimo/layermap.h | 6 +++--- lib/include/srslte/phy/mimo/precoding.h | 6 +++--- lib/include/srslte/phy/modem/demod_hard.h | 6 +++--- lib/include/srslte/phy/modem/demod_soft.h | 6 +++--- lib/include/srslte/phy/modem/mod.h | 6 +++--- lib/include/srslte/phy/modem/modem_table.h | 6 +++--- lib/include/srslte/phy/phch/cqi.h | 6 +++--- lib/include/srslte/phy/phch/dci.h | 4 ++-- lib/include/srslte/phy/phch/pbch.h | 6 +++--- lib/include/srslte/phy/phch/pcfich.h | 6 +++--- lib/include/srslte/phy/phch/pdcch.h | 6 +++--- lib/include/srslte/phy/phch/pdsch.h | 6 +++--- lib/include/srslte/phy/phch/pdsch_cfg.h | 6 +++--- lib/include/srslte/phy/phch/phich.h | 6 +++--- lib/include/srslte/phy/phch/pmch.h | 6 +++--- lib/include/srslte/phy/phch/prach.h | 6 +++--- lib/include/srslte/phy/phch/pucch.h | 6 +++--- lib/include/srslte/phy/phch/pusch.h | 6 +++--- lib/include/srslte/phy/phch/pusch_cfg.h | 6 +++--- lib/include/srslte/phy/phch/ra.h | 6 +++--- lib/include/srslte/phy/phch/regs.h | 6 +++--- lib/include/srslte/phy/phch/sch.h | 6 +++--- lib/include/srslte/phy/phch/uci.h | 6 +++--- lib/include/srslte/phy/resampling/decim.h | 6 +++--- lib/include/srslte/phy/resampling/interp.h | 6 +++--- lib/include/srslte/phy/resampling/resample_arb.h | 6 +++--- lib/include/srslte/phy/rf/rf.h | 6 +++--- lib/include/srslte/phy/rf/rf_utils.h | 3 +++ lib/include/srslte/phy/scrambling/scrambling.h | 6 +++--- lib/include/srslte/phy/sync/cfo.h | 6 +++--- lib/include/srslte/phy/sync/cp.h | 6 +++--- lib/include/srslte/phy/sync/pss.h | 6 +++--- lib/include/srslte/phy/sync/sfo.h | 6 +++--- lib/include/srslte/phy/sync/sss.h | 6 +++--- lib/include/srslte/phy/sync/sync.h | 6 +++--- lib/include/srslte/phy/ue/ue_cell_search.h | 6 +++--- lib/include/srslte/phy/ue/ue_dl.h | 6 +++--- lib/include/srslte/phy/ue/ue_mib.h | 6 +++--- lib/include/srslte/phy/ue/ue_phy.h | 6 +++--- lib/include/srslte/phy/ue/ue_sync.h | 6 +++--- lib/include/srslte/phy/ue/ue_ul.h | 6 +++--- lib/include/srslte/phy/utils/bit.h | 6 +++--- lib/include/srslte/phy/utils/cexptab.h | 6 +++--- lib/include/srslte/phy/utils/convolution.h | 6 +++--- lib/include/srslte/phy/utils/debug.h | 6 +++--- lib/include/srslte/phy/utils/filter.h | 7 ++++--- lib/include/srslte/phy/utils/mat.h | 2 +- lib/include/srslte/phy/utils/ringbuffer.h | 6 +++--- lib/include/srslte/phy/utils/simd.h | 6 +++--- lib/include/srslte/phy/utils/vector.h | 6 +++--- lib/include/srslte/phy/utils/vector_simd.h | 6 +++--- lib/include/srslte/radio/radio.h | 6 +++--- lib/include/srslte/radio/radio_multi.h | 6 +++--- lib/include/srslte/srslte.h | 6 +++--- lib/include/srslte/upper/pdcp.h | 8 ++++---- lib/include/srslte/upper/pdcp_entity.h | 8 ++++---- lib/include/srslte/upper/rlc.h | 6 +++--- lib/include/srslte/upper/rlc_am.h | 8 ++++---- lib/include/srslte/upper/rlc_common.h | 6 +++--- lib/include/srslte/upper/rlc_entity.h | 8 ++++---- lib/include/srslte/upper/rlc_interface.h | 6 +++--- lib/include/srslte/upper/rlc_metrics.h | 8 ++++---- lib/include/srslte/upper/rlc_tm.h | 6 +++--- lib/include/srslte/upper/rlc_um.h | 6 +++--- lib/include/srslte/version.h.in | 4 ++-- srsenb/hdr/cfg_parser.h | 4 ++-- srsenb/hdr/enb.h | 6 +++--- srsenb/hdr/mac/mac.h | 8 ++++---- srsenb/hdr/mac/mac_metrics.h | 6 +++--- srsenb/hdr/mac/scheduler.h | 6 +++--- srsenb/hdr/mac/scheduler_harq.h | 6 +++--- srsenb/hdr/mac/scheduler_metric.h | 6 +++--- srsenb/hdr/mac/scheduler_ue.h | 6 +++--- srsenb/hdr/mac/ue.h | 6 +++--- srsenb/hdr/metrics_stdout.h | 6 +++--- srsenb/hdr/parser.h | 4 ++-- srsenb/hdr/phy/phch_common.h | 6 +++--- srsenb/hdr/phy/phch_worker.h | 6 +++--- srsenb/hdr/phy/phy.h | 6 +++--- srsenb/hdr/phy/phy_metrics.h | 6 +++--- srsenb/hdr/phy/prach_worker.h | 6 +++--- srsenb/hdr/phy/txrx.h | 6 +++--- srsenb/hdr/upper/common_enb.h | 6 +++--- srsenb/hdr/upper/gtpu.h | 6 +++--- srsenb/hdr/upper/pdcp.h | 6 +++--- srsenb/hdr/upper/rlc.h | 6 +++--- srsenb/hdr/upper/rrc.h | 6 +++--- srsenb/hdr/upper/rrc_metrics.h | 6 +++--- srsenb/hdr/upper/s1ap.h | 6 +++--- srsenb/hdr/upper/s1ap_metrics.h | 6 +++--- srsepc/hdr/hss/hss.h | 6 +++--- srsepc/hdr/mme/mme.h | 6 +++--- srsepc/hdr/mme/mme_gtpc.h | 6 +++--- srsepc/hdr/mme/s1ap.h | 6 +++--- srsepc/hdr/mme/s1ap_common.h | 7 ++++--- srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h | 6 +++--- srsepc/hdr/mme/s1ap_mngmt_proc.h | 6 +++--- srsepc/hdr/mme/s1ap_nas_transport.h | 6 +++--- srsepc/hdr/spgw/spgw.h | 6 +++--- srsue/hdr/mac/demux.h | 6 +++--- srsue/hdr/mac/dl_harq.h | 6 +++--- srsue/hdr/mac/dl_sps.h | 6 +++--- srsue/hdr/mac/mac.h | 6 +++--- srsue/hdr/mac/mac_metrics.h | 6 +++--- srsue/hdr/mac/mux.h | 6 +++--- srsue/hdr/mac/proc.h | 6 +++--- srsue/hdr/mac/proc_bsr.h | 6 +++--- srsue/hdr/mac/proc_phr.h | 6 +++--- srsue/hdr/mac/proc_ra.h | 6 +++--- srsue/hdr/mac/proc_sr.h | 6 +++--- srsue/hdr/mac/ul_harq.h | 6 +++--- srsue/hdr/mac/ul_sps.h | 6 +++--- srsue/hdr/metrics_csv.h | 6 +++--- srsue/hdr/metrics_stdout.h | 6 +++--- srsue/hdr/phy/phch_common.h | 6 +++--- srsue/hdr/phy/phch_recv.h | 6 +++--- srsue/hdr/phy/phch_worker.h | 6 +++--- srsue/hdr/phy/phy.h | 6 +++--- srsue/hdr/phy/phy_metrics.h | 6 +++--- srsue/hdr/phy/prach.h | 6 +++--- srsue/hdr/ue.h | 6 +++--- srsue/hdr/ue_base.h | 6 +++--- srsue/hdr/ue_metrics_interface.h | 6 +++--- srsue/hdr/upper/gw.h | 6 +++--- srsue/hdr/upper/gw_metrics.h | 6 +++--- srsue/hdr/upper/nas.h | 6 +++--- srsue/hdr/upper/rrc.h | 6 +++--- srsue/hdr/upper/rrc_common.h | 6 +++--- srsue/hdr/upper/usim.h | 6 +++--- 209 files changed, 640 insertions(+), 631 deletions(-) diff --git a/lib/include/srslte/asn1/gtpc.h b/lib/include/srslte/asn1/gtpc.h index d204cd31d..3c2a3247f 100644 --- a/lib/include/srslte/asn1/gtpc.h +++ b/lib/include/srslte/asn1/gtpc.h @@ -21,8 +21,8 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef GTPC_V2_H -#define GTPC_V2_H +#ifndef SRSLTE_GTPC_H +#define SRSLTE_GTPC_H #include #include "srslte/asn1/gtpc_msg.h" @@ -94,4 +94,4 @@ typedef struct gtpc_pdu union gtpc_msg_choice choice; }gtpc_pdu_t; }//namespace -#endif +#endif // SRSLTE_GTPC_H diff --git a/lib/include/srslte/asn1/gtpc_ies.h b/lib/include/srslte/asn1/gtpc_ies.h index 657fc7c16..0ddcfaacb 100644 --- a/lib/include/srslte/asn1/gtpc_ies.h +++ b/lib/include/srslte/asn1/gtpc_ies.h @@ -22,8 +22,8 @@ * */ -#ifndef GTPC_IES_H -#define GTPC_IES_H +#ifndef SRSLTE_GTPC_IES_H +#define SRSLTE_GTPC_IES_H #include "srslte/phy/io/netsource.h" @@ -426,4 +426,4 @@ typedef struct gtpc_f_teid_ie //locally, according to the rules of TS 29.274 v10.14.0 Section 7. } //namespace -#endif //GTPC_IES_H +#endif // SRSLTE_GTPC_IES_H diff --git a/lib/include/srslte/asn1/gtpc_msg.h b/lib/include/srslte/asn1/gtpc_msg.h index 159be0c80..61591d7c4 100644 --- a/lib/include/srslte/asn1/gtpc_msg.h +++ b/lib/include/srslte/asn1/gtpc_msg.h @@ -21,8 +21,8 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef GTPC_V2_MSG_H -#define GTPC_V2_MSG_H +#ifndef SRSLTE_GTPC_MSG_H +#define SRSLTE_GTPC_MSG_H #include "srslte/asn1/gtpc_ies.h" @@ -442,4 +442,4 @@ struct gtpc_release_access_bearers_request } //namespace -#endif //GTPC_V2_MSG_H +#endif // SRSLTE_GTPC_MSG_H diff --git a/lib/include/srslte/asn1/liblte_common.h b/lib/include/srslte/asn1/liblte_common.h index 36fb32190..21d962748 100644 --- a/lib/include/srslte/asn1/liblte_common.h +++ b/lib/include/srslte/asn1/liblte_common.h @@ -33,8 +33,8 @@ *******************************************************************************/ -#ifndef __LIBLTE_COMMON_H__ -#define __LIBLTE_COMMON_H__ +#ifndef SRSLTE_LIBLTE_COMMON_H +#define SRSLTE_LIBLTE_COMMON_H /******************************************************************************* INCLUDES @@ -244,4 +244,4 @@ void liblte_align_up(uint8_t **ptr, uint32_t align); *********************************************************************/ void liblte_align_up_zero(uint8_t **ptr, uint32_t align); -#endif /* __LIBLTE_COMMON_H__ */ +#endif // SRSLTE_LIBLTE_COMMON_H diff --git a/lib/include/srslte/asn1/liblte_mme.h b/lib/include/srslte/asn1/liblte_mme.h index 85b8b2241..31b1a49df 100644 --- a/lib/include/srslte/asn1/liblte_mme.h +++ b/lib/include/srslte/asn1/liblte_mme.h @@ -35,8 +35,8 @@ *******************************************************************************/ -#ifndef __LIBLTE_MME_H__ -#define __LIBLTE_MME_H__ +#ifndef SRSLTE_LIBLTE_MME_H +#define SRSLTE_LIBLTE_MME_H /******************************************************************************* INCLUDES @@ -4038,4 +4038,4 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_pdn_disconnect_request_msg(LIBLTE_MME_PDN_DISC LIBLTE_ERROR_ENUM liblte_mme_unpack_pdn_disconnect_request_msg(LIBLTE_BYTE_MSG_STRUCT *msg, LIBLTE_MME_PDN_DISCONNECT_REQUEST_MSG_STRUCT *pdn_discon_req); -#endif /* __LIBLTE_MME_H__ */ +#endif // SRSLTE_LIBLTE_MME_H diff --git a/lib/include/srslte/asn1/liblte_rrc.h b/lib/include/srslte/asn1/liblte_rrc.h index e0fb43aef..4fdff34e2 100644 --- a/lib/include/srslte/asn1/liblte_rrc.h +++ b/lib/include/srslte/asn1/liblte_rrc.h @@ -51,8 +51,8 @@ *******************************************************************************/ -#ifndef __LIBLTE_RRC_H__ -#define __LIBLTE_RRC_H__ +#ifndef SRSLTE_LIBLTE_RRC_H +#define SRSLTE_LIBLTE_RRC_H /******************************************************************************* INCLUDES @@ -7013,4 +7013,4 @@ LIBLTE_ERROR_ENUM liblte_rrc_pack_ul_dcch_msg(LIBLTE_RRC_UL_DCCH_MSG_STRUCT *ul_ LIBLTE_ERROR_ENUM liblte_rrc_unpack_ul_dcch_msg(LIBLTE_BIT_MSG_STRUCT *msg, LIBLTE_RRC_UL_DCCH_MSG_STRUCT *ul_dcch_msg); -#endif /* __LIBLTE_RRC_H__ */ +#endif // SRSLTE_LIBLTE_RRC_H diff --git a/lib/include/srslte/asn1/liblte_s1ap.h b/lib/include/srslte/asn1/liblte_s1ap.h index 077ddac66..0874ec753 100644 --- a/lib/include/srslte/asn1/liblte_s1ap.h +++ b/lib/include/srslte/asn1/liblte_s1ap.h @@ -4,8 +4,8 @@ /* ********************************************************************************/ -#ifndef LIBLTE_S1AP_H -#define LIBLTE_S1AP_H +#ifndef SRSLTE_LIBLTE_S1AP_H +#define SRSLTE_LIBLTE_S1AP_H /******************************************************************************* /* Warnings/Todos @@ -10352,4 +10352,4 @@ LIBLTE_ERROR_ENUM liblte_s1ap_pack_s1ap_pdu( LIBLTE_ERROR_ENUM liblte_s1ap_unpack_s1ap_pdu( LIBLTE_BYTE_MSG_STRUCT *msg, LIBLTE_S1AP_S1AP_PDU_STRUCT *s1ap_pdu); -#endif // LIBLTE_S1AP_H +#endif // SRSLTE_LIBLTE_S1AP_H diff --git a/lib/include/srslte/build_info.h.in b/lib/include/srslte/build_info.h.in index 90dac1dbb..5409ab077 100644 --- a/lib/include/srslte/build_info.h.in +++ b/lib/include/srslte/build_info.h.in @@ -25,8 +25,8 @@ * */ -#ifndef BUILD_INFO_ -#define BUILD_INFO_ +#ifndef SRSLTE_BUILD_INFO_H_IN +#define SRSLTE_BUILD_INFO_H_IN # ifdef __cplusplus extern "C" { diff --git a/lib/include/srslte/common/bcd_helpers.h b/lib/include/srslte/common/bcd_helpers.h index 10bed4347..b145a2d5a 100644 --- a/lib/include/srslte/common/bcd_helpers.h +++ b/lib/include/srslte/common/bcd_helpers.h @@ -24,8 +24,8 @@ * */ -#ifndef BCD_HELPERS -#define BCD_HELPERS +#ifndef SRSLTE_BCD_HELPERS_H +#define SRSLTE_BCD_HELPERS_H #include #include @@ -194,4 +194,4 @@ inline void s1ap_mccmnc_to_plmn(uint16_t mcc, uint16_t mnc, uint32_t *plmn) } // namespace srslte -#endif // BCD_HELPERS +#endif // SRSLTE_BCD_HELPERS_H diff --git a/lib/include/srslte/common/block_queue.h b/lib/include/srslte/common/block_queue.h index b4b312b60..b04a91985 100644 --- a/lib/include/srslte/common/block_queue.h +++ b/lib/include/srslte/common/block_queue.h @@ -24,8 +24,8 @@ * */ -#ifndef BLOCK_QUEUE -#define BLOCK_QUEUE +#ifndef SRSLTE_BLOCK_QUEUE_H +#define SRSLTE_BLOCK_QUEUE_H #include #include @@ -94,4 +94,4 @@ private: } -#endif \ No newline at end of file +#endif // SRSLTE_BLOCK_QUEUE_H \ No newline at end of file diff --git a/lib/include/srslte/common/buffer_pool.h b/lib/include/srslte/common/buffer_pool.h index 76634a697..1895c8330 100644 --- a/lib/include/srslte/common/buffer_pool.h +++ b/lib/include/srslte/common/buffer_pool.h @@ -24,8 +24,8 @@ * */ -#ifndef BUFFER_POOL_H -#define BUFFER_POOL_H +#ifndef SRSLTE_BUFFER_POOL_H +#define SRSLTE_BUFFER_POOL_H #include #include @@ -187,4 +187,4 @@ private: } // namespace srsue -#endif // BUFFER_POOL_H +#endif // SRSLTE_BUFFER_POOL_H diff --git a/lib/include/srslte/common/common.h b/lib/include/srslte/common/common.h index de9f6d5aa..754b7423d 100644 --- a/lib/include/srslte/common/common.h +++ b/lib/include/srslte/common/common.h @@ -24,8 +24,8 @@ * */ -#ifndef COMMON_H -#define COMMON_H +#ifndef SRSLTE_COMMON_H +#define SRSLTE_COMMON_H /******************************************************************************* INCLUDES @@ -239,6 +239,6 @@ private: }; -} // namespace srsue +} // namespace srslte -#endif // COMMON_H +#endif // SRSLTE_COMMON_H diff --git a/lib/include/srslte/common/config.h b/lib/include/srslte/common/config.h index 3231355fa..ed95631cd 100644 --- a/lib/include/srslte/common/config.h +++ b/lib/include/srslte/common/config.h @@ -24,8 +24,8 @@ * */ -#ifndef CONFIG_H -#define CONFIG_H +#ifndef SRSLTE_CONFIG_H +#define SRSLTE_CONFIG_H // Generic helper definitions for shared library support #if defined _WIN32 || defined __CYGWIN__ @@ -54,4 +54,4 @@ // cf_t definition typedef _Complex float cf_t; -#endif // CONFIG_H +#endif // SRSLTE_CONFIG_H diff --git a/lib/include/srslte/common/interfaces_common.h b/lib/include/srslte/common/interfaces_common.h index e7de90ea1..50eb024b5 100644 --- a/lib/include/srslte/common/interfaces_common.h +++ b/lib/include/srslte/common/interfaces_common.h @@ -24,8 +24,8 @@ * */ -#ifndef INTERFACE_COMMON_H -#define INTERFACE_COMMON_H +#ifndef SRSLTE_INTERFACES_COMMON_H +#define SRSLTE_INTERFACES_COMMON_H #include "srslte/common/timers.h" #include "srslte/common/security.h" @@ -96,4 +96,4 @@ public: } -#endif +#endif // SRSLTE_INTERFACES_COMMON_H diff --git a/lib/include/srslte/common/liblte_security.h b/lib/include/srslte/common/liblte_security.h index 02cc42ca8..8dc31f341 100644 --- a/lib/include/srslte/common/liblte_security.h +++ b/lib/include/srslte/common/liblte_security.h @@ -29,8 +29,8 @@ *******************************************************************************/ -#ifndef __LIBLTE_SECURITY_H__ -#define __LIBLTE_SECURITY_H__ +#ifndef SRSLTE_LIBLTE_SECURITY_H +#define SRSLTE_LIBLTE_SECURITY_H /******************************************************************************* INCLUDES @@ -345,4 +345,4 @@ LIBLTE_ERROR_ENUM liblte_security_milenage_f5_star(uint8 *k, uint8 *rand, uint8 *ak); -#endif /* __LIBLTE_SECURITY_H__ */ +#endif // SRSLTE_LIBLTE_SECURITY_H diff --git a/lib/include/srslte/common/liblte_ssl.h b/lib/include/srslte/common/liblte_ssl.h index d96c728ab..2ac4e794f 100644 --- a/lib/include/srslte/common/liblte_ssl.h +++ b/lib/include/srslte/common/liblte_ssl.h @@ -1,5 +1,5 @@ -#ifndef __LIBLTE_SSL_H__ -#define __LIBLTE_SSL_H__ +#ifndef SRSLTE_LIBLTE_SSL_H +#define SRSLTE_LIBLTE_SSL_H #ifdef HAVE_POLARSSL @@ -62,4 +62,4 @@ void sha256(const unsigned char *key, size_t keylen, #endif // HAVE_MBEDTLS -#endif // __LIBLTE_SSL_H__ +#endif // SRSLTE_LIBLTE_SSL_H diff --git a/lib/include/srslte/common/log.h b/lib/include/srslte/common/log.h index 45c359629..c7cec8488 100644 --- a/lib/include/srslte/common/log.h +++ b/lib/include/srslte/common/log.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef LOG_H -#define LOG_H +#ifndef SRSLTE_LOG_H +#define SRSLTE_LOG_H #include #include @@ -149,5 +149,5 @@ protected: } // namespace srslte -#endif // LOG_H +#endif // SRSLTE_LOG_H diff --git a/lib/include/srslte/common/log_filter.h b/lib/include/srslte/common/log_filter.h index 430a59199..2bcc510b7 100644 --- a/lib/include/srslte/common/log_filter.h +++ b/lib/include/srslte/common/log_filter.h @@ -32,8 +32,8 @@ * common logger object. *****************************************************************************/ -#ifndef LOG_FILTER_H -#define LOG_FILTER_H +#ifndef SRSLTE_LOG_FILTER_H +#define SRSLTE_LOG_FILTER_H #include #include @@ -98,4 +98,4 @@ private: } // namespace srsue -#endif // LOG_FILTER_H +#endif // SRSLTE_LOG_FILTER_H diff --git a/lib/include/srslte/common/logger.h b/lib/include/srslte/common/logger.h index 95e52922c..ed352cd5f 100644 --- a/lib/include/srslte/common/logger.h +++ b/lib/include/srslte/common/logger.h @@ -29,8 +29,8 @@ * Description: Interface for logging output *****************************************************************************/ -#ifndef LOGGER_H -#define LOGGER_H +#ifndef SRSLTE_LOGGER_H +#define SRSLTE_LOGGER_H #include #include @@ -45,4 +45,4 @@ public: } // namespace srslte -#endif // LOGGER_H +#endif // SRSLTE_LOGGER_H diff --git a/lib/include/srslte/common/logger_file.h b/lib/include/srslte/common/logger_file.h index d67a83220..f0bd5a15b 100644 --- a/lib/include/srslte/common/logger_file.h +++ b/lib/include/srslte/common/logger_file.h @@ -32,8 +32,8 @@ * increase queue size. If empty, consumer blocks. *****************************************************************************/ -#ifndef LOGGER_FILE_H -#define LOGGER_FILE_H +#ifndef SRSLTE_LOGGER_FILE_H +#define SRSLTE_LOGGER_FILE_H #include #include @@ -74,6 +74,6 @@ private: std::deque buffer; }; -} // namespace srsue +} // namespace srslte -#endif // LOGGER_H +#endif // SRSLTE_LOGGER_FILE_H diff --git a/lib/include/srslte/common/logger_stdout.h b/lib/include/srslte/common/logger_stdout.h index b76faadaf..4aab21d6b 100644 --- a/lib/include/srslte/common/logger_stdout.h +++ b/lib/include/srslte/common/logger_stdout.h @@ -29,8 +29,8 @@ * Description: Interface for logging output *****************************************************************************/ -#ifndef LOGGER_STDOUT_H -#define LOGGER_STDOUT_H +#ifndef SRSLTE_LOGGER_STDOUT_H +#define SRSLTE_LOGGER_STDOUT_H #include #include @@ -51,4 +51,4 @@ namespace srslte { } // namespace srslte -#endif // LOGGER_H +#endif // SRSLTE_LOGGER_STDOUT_H diff --git a/lib/include/srslte/common/mac_pcap.h b/lib/include/srslte/common/mac_pcap.h index 26a8f20bb..b403c8c49 100644 --- a/lib/include/srslte/common/mac_pcap.h +++ b/lib/include/srslte/common/mac_pcap.h @@ -24,8 +24,8 @@ * */ -#ifndef MACPCAP_H -#define MACPCAP_H +#ifndef SRSLTE_MAC_PCAP_H +#define SRSLTE_MAC_PCAP_H #include #include "srslte/common/pcap.h" @@ -59,6 +59,6 @@ private: uint16_t crnti_, uint8_t direction, uint8_t rnti_type); }; -} // namespace srsue +} // namespace srslte -#endif // MACPCAP_H +#endif // SRSLTE_MAC_PCAP_H diff --git a/lib/include/srslte/common/metrics_hub.h b/lib/include/srslte/common/metrics_hub.h index 05ab4c5fa..a73f3d90e 100644 --- a/lib/include/srslte/common/metrics_hub.h +++ b/lib/include/srslte/common/metrics_hub.h @@ -5,8 +5,8 @@ * to get metrics *****************************************************************************/ -#ifndef METRICS_HUB_H -#define METRICS_HUB_H +#ifndef SRSLTE_METRICS_HUB_H +#define SRSLTE_METRICS_HUB_H #include #include "srslte/common/threads.h" @@ -79,4 +79,4 @@ private: } // namespace srslte -#endif // METRICS_HUB_H +#endif // SRSLTE_METRICS_HUB_H diff --git a/lib/include/srslte/common/msg_queue.h b/lib/include/srslte/common/msg_queue.h index e8b8c742a..0dcdc2a55 100644 --- a/lib/include/srslte/common/msg_queue.h +++ b/lib/include/srslte/common/msg_queue.h @@ -30,8 +30,8 @@ * Reference: *****************************************************************************/ -#ifndef MSG_QUEUE_H -#define MSG_QUEUE_H +#ifndef SRSLTE_MSG_QUEUE_H +#define SRSLTE_MSG_QUEUE_H #include "srslte/common/common.h" #include @@ -149,7 +149,7 @@ private: uint32_t tail; }; -} // namespace srsue +} // namespace srslte -#endif // MSG_QUEUE_H +#endif // SRSLTE_MSG_QUEUE_H diff --git a/lib/include/srslte/common/nas_pcap.h b/lib/include/srslte/common/nas_pcap.h index 68fcabb73..061ba5010 100644 --- a/lib/include/srslte/common/nas_pcap.h +++ b/lib/include/srslte/common/nas_pcap.h @@ -1,5 +1,5 @@ -#ifndef NAS_PCAP_H -#define NAS_PCAP_H +#ifndef SRSLTE_NAS_PCAP_H +#define SRSLTE_NAS_PCAP_H #include "srslte/common/pcap.h" @@ -20,6 +20,6 @@ private: void pack_and_write(uint8_t* pdu, uint32_t pdu_len_bytes); }; -} //namespace srsue +} //namespace srslte -#endif // NAS_PCAP_H +#endif // SRSLTE_NAS_PCAP_H diff --git a/lib/include/srslte/common/pcap.h b/lib/include/srslte/common/pcap.h index ce4fcf541..d52547312 100644 --- a/lib/include/srslte/common/pcap.h +++ b/lib/include/srslte/common/pcap.h @@ -24,8 +24,8 @@ * */ -#ifndef UEPCAP_H -#define UEPCAP_H +#ifndef SRSLTE_PCAP_H +#define SRSLTE_PCAP_H #include #include @@ -247,4 +247,4 @@ inline int LTE_PCAP_NAS_WritePDU(FILE *fd, NAS_Context_Info_t *context, return 1; } -#endif /* UEPCAP_H */ +#endif // SRSLTE_PCAP_H diff --git a/lib/include/srslte/common/pdu.h b/lib/include/srslte/common/pdu.h index 5d0f5a235..cc2bb64f5 100644 --- a/lib/include/srslte/common/pdu.h +++ b/lib/include/srslte/common/pdu.h @@ -24,8 +24,8 @@ * */ -#ifndef MACPDU_H -#define MACPDU_H +#ifndef SRSLTE_PDU_H +#define SRSLTE_PDU_H #include #include "srslte/common/log.h" @@ -338,6 +338,6 @@ private: uint8_t backoff_indicator; }; -} // namespace srsue +} // namespace srslte -#endif // MACPDU_H +#endif // SRSLTE_PDU_H diff --git a/lib/include/srslte/common/pdu_queue.h b/lib/include/srslte/common/pdu_queue.h index 40e0f2dd2..a0c2b1da9 100644 --- a/lib/include/srslte/common/pdu_queue.h +++ b/lib/include/srslte/common/pdu_queue.h @@ -24,8 +24,8 @@ * */ -#ifndef PDUPROC_H -#define PDUPROC_H +#ifndef SRSLTE_PDU_QUEUE_H +#define SRSLTE_PDU_QUEUE_H #include "srslte/common/log.h" #include "srslte/common/block_queue.h" @@ -79,7 +79,7 @@ private: } // namespace srslte -#endif // PDUPROC_H +#endif // SRSLTE_PDU_QUEUE_H diff --git a/lib/include/srslte/common/security.h b/lib/include/srslte/common/security.h index 9ba2616d1..80b4c0c0e 100644 --- a/lib/include/srslte/common/security.h +++ b/lib/include/srslte/common/security.h @@ -24,8 +24,8 @@ * */ -#ifndef SECURITY_H -#define SECURITY_H +#ifndef SRSLTE_SECURITY_H +#define SRSLTE_SECURITY_H /****************************************************************************** * Common security header - wraps ciphering/integrity check algorithms. @@ -175,6 +175,6 @@ uint8_t security_milenage_f5_star( uint8_t *k, uint8_t *ak); -} // namespace srsue +} // namespace srslte -#endif // SECURITY_H +#endif // SRSLTE_SECURITY_H diff --git a/lib/include/srslte/common/snow_3g.h b/lib/include/srslte/common/snow_3g.h index c20e6a626..d4c742bb7 100644 --- a/lib/include/srslte/common/snow_3g.h +++ b/lib/include/srslte/common/snow_3g.h @@ -9,6 +9,8 @@ * and Integrity Algorithms UEA2 & UIA2. * Document 2: SNOW 3G Specification" *---------------------------------------------------------*/ +#ifndef SRSLTE_SNOW_3G_H +#define SRSLTE_SNOW_3G_H #include #include @@ -69,3 +71,4 @@ void snow3g_f8( u8 *key, u32 count, u32 bearer, u32 dir, \ u8* snow3g_f9( u8* key, u32 count, u32 fresh, u32 dir, \ u8 *data, u64 length); +#endif // SRSLTE_SNOW_3G_H \ No newline at end of file diff --git a/lib/include/srslte/common/task_dispatcher.h b/lib/include/srslte/common/task_dispatcher.h index 5a86fc311..c1d223a2b 100644 --- a/lib/include/srslte/common/task_dispatcher.h +++ b/lib/include/srslte/common/task_dispatcher.h @@ -30,8 +30,8 @@ * Reference: *****************************************************************************/ -#ifndef TASK_DISPATCHER_H -#define TASK_DISPATCHER_H +#ifndef SRSLTE_TASK_DISPATCHER_H +#define SRSLTE_TASK_DISPATCHER_H #include #include @@ -56,6 +56,6 @@ private: bool running; }; -} // namespace srsue +} // namespace srslte -#endif // TASK_DISPATCHER_H +#endif // SRSLTE_TASK_DISPATCHER_H diff --git a/lib/include/srslte/common/thread_pool.h b/lib/include/srslte/common/thread_pool.h index 812ee2433..865fc10d9 100644 --- a/lib/include/srslte/common/thread_pool.h +++ b/lib/include/srslte/common/thread_pool.h @@ -31,8 +31,8 @@ * Reference: *****************************************************************************/ -#ifndef THREAD_POOL_H -#define THREAD_POOL_H +#ifndef SRSLTE_THREAD_POOL_H +#define SRSLTE_THREAD_POOL_H #include #include @@ -102,4 +102,4 @@ private: }; } -#endif +#endif // SRSLTE_THREAD_POOL_H diff --git a/lib/include/srslte/common/threads.h b/lib/include/srslte/common/threads.h index 949ece195..e58f056b5 100644 --- a/lib/include/srslte/common/threads.h +++ b/lib/include/srslte/common/threads.h @@ -24,6 +24,7 @@ * */ + #include #include #include @@ -46,8 +47,8 @@ #ifdef __cplusplus } -#ifndef THREADS_ -#define THREADS_ +#ifndef SRSLTE_THREADS_H +#define SRSLTE_THREADS_H class thread { @@ -159,7 +160,7 @@ private: -#endif // THREADS_ +#endif // SRSLTE_THREADS_H #endif // __cplusplus diff --git a/lib/include/srslte/common/timeout.h b/lib/include/srslte/common/timeout.h index 4174b0237..bca09da31 100644 --- a/lib/include/srslte/common/timeout.h +++ b/lib/include/srslte/common/timeout.h @@ -31,8 +31,8 @@ * Reference: *****************************************************************************/ -#ifndef TIMEOUT_H -#define TIMEOUT_H +#ifndef SRSLTE_TIMEOUT_H +#define SRSLTE_TIMEOUT_H #include #include @@ -126,6 +126,6 @@ private: int duration_msec; }; -} // namespace srsue +} // namespace srslte -#endif // TIMEOUT_H +#endif // SRSLTE_TIMEOUT_H diff --git a/lib/include/srslte/common/timers.h b/lib/include/srslte/common/timers.h index 5e8b1cfd5..a2d8dc15a 100644 --- a/lib/include/srslte/common/timers.h +++ b/lib/include/srslte/common/timers.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef TIMERS_H -#define TIMERS_H +#ifndef SRSLTE_TIMERS_H +#define SRSLTE_TIMERS_H #include #include @@ -173,4 +173,4 @@ private: } // namespace srslte -#endif // TIMERS_H +#endif // SRSLTE_TIMERS_H diff --git a/lib/include/srslte/common/trace.h b/lib/include/srslte/common/trace.h index 64d55e460..00c7739f6 100644 --- a/lib/include/srslte/common/trace.h +++ b/lib/include/srslte/common/trace.h @@ -30,8 +30,8 @@ * Reference: *****************************************************************************/ -#ifndef TRACE_H -#define TRACE_H +#ifndef SRSLTE_TRACE_H +#define SRSLTE_TRACE_H #include #include @@ -98,4 +98,4 @@ private: } // namespace srslte -#endif // TRACE_H +#endif // SRSLTE_TRACE_H diff --git a/lib/include/srslte/common/tti_sync.h b/lib/include/srslte/common/tti_sync.h index fd62f442b..dd018f889 100644 --- a/lib/include/srslte/common/tti_sync.h +++ b/lib/include/srslte/common/tti_sync.h @@ -33,8 +33,8 @@ * Reference: *****************************************************************************/ -#ifndef TTISYNC_H -#define TTISYNC_H +#ifndef SRSLTE_TTI_SYNC_H +#define SRSLTE_TTI_SYNC_H #include @@ -77,4 +77,4 @@ class tti_sync } // namespace srsue -#endif // TTISYNC_H +#endif // SRSLTE_TTI_SYNC_H diff --git a/lib/include/srslte/common/tti_sync_cv.h b/lib/include/srslte/common/tti_sync_cv.h index 887ac4f04..2ba975faa 100644 --- a/lib/include/srslte/common/tti_sync_cv.h +++ b/lib/include/srslte/common/tti_sync_cv.h @@ -30,8 +30,8 @@ * Reference: *****************************************************************************/ -#ifndef TTISYNC_CV_H -#define TTISYNC_CV_H +#ifndef SRSLTE_TTI_SYNC_CV_H +#define SRSLTE_TTI_SYNC_CV_H #include #include "srslte/common/tti_sync.h" @@ -54,6 +54,6 @@ class tti_sync_cv : public tti_sync pthread_mutex_t mutex; }; -} // namespace srsue +} // namespace srslte -#endif // TTISYNC_CV_H +#endif // SRSLTE_TTI_SYNC_CV_H diff --git a/lib/include/srslte/config.h b/lib/include/srslte/config.h index 1e9d27aac..02c43777f 100644 --- a/lib/include/srslte/config.h +++ b/lib/include/srslte/config.h @@ -24,8 +24,8 @@ * */ -#ifndef CONFIG_H -#define CONFIG_H +#ifndef SRSLTE_CONFIG_H +#define SRSLTE_CONFIG_H // Generic helper definitions for shared library support #if defined _WIN32 || defined __CYGWIN__ @@ -64,4 +64,4 @@ typedef _Complex float cf_t; typedef _Complex short int c16_t; #endif /* ENABLE_C16 */ -#endif // CONFIG_H +#endif // SRSLTE_CONFIG_H diff --git a/lib/include/srslte/interfaces/enb_interfaces.h b/lib/include/srslte/interfaces/enb_interfaces.h index cd7d10020..cad5c5eb1 100644 --- a/lib/include/srslte/interfaces/enb_interfaces.h +++ b/lib/include/srslte/interfaces/enb_interfaces.h @@ -36,8 +36,8 @@ #include -#ifndef ENBINTERFACES_H -#define ENBINTERFACES_H +#ifndef SRSLTE_ENB_INTERFACES_H +#define SRSLTE_ENB_INTERFACES_H namespace srsenb { @@ -272,4 +272,4 @@ public: } -#endif +#endif // SRSLTE_ENB_INTERFACES_H diff --git a/lib/include/srslte/interfaces/enb_metrics_interface.h b/lib/include/srslte/interfaces/enb_metrics_interface.h index ee00e3453..6c8b2e740 100644 --- a/lib/include/srslte/interfaces/enb_metrics_interface.h +++ b/lib/include/srslte/interfaces/enb_metrics_interface.h @@ -24,8 +24,8 @@ * */ -#ifndef ENB_METRICS_INTERFACE_H -#define ENB_METRICS_INTERFACE_H +#ifndef SRSLTE_ENB_METRICS_INTERFACE_H +#define SRSLTE_ENB_METRICS_INTERFACE_H #include @@ -64,4 +64,4 @@ public: } // namespace srsenb -#endif // ENB_METRICS_INTERFACE_H +#endif // SRSLTE_ENB_METRICS_INTERFACE_H diff --git a/lib/include/srslte/interfaces/epc_interfaces.h b/lib/include/srslte/interfaces/epc_interfaces.h index 21646628a..60238b7f9 100644 --- a/lib/include/srslte/interfaces/epc_interfaces.h +++ b/lib/include/srslte/interfaces/epc_interfaces.h @@ -1,5 +1,5 @@ -#ifndef EPC_INTERFACE_H -#define EPC_INTERFACE_H +#ifndef SRSLTE_EPC_INTERFACES_H +#define SRSLTE_EPC_INTERFACES_H #include "srslte/srslte.h" @@ -15,4 +15,4 @@ public: }; } -#endif // ENB_METRICS_INTERFACE_H +#endif // SRSLTE_EPC_INTERFACES_H diff --git a/lib/include/srslte/interfaces/sched_interface.h b/lib/include/srslte/interfaces/sched_interface.h index 562499dfb..5160b4490 100644 --- a/lib/include/srslte/interfaces/sched_interface.h +++ b/lib/include/srslte/interfaces/sched_interface.h @@ -26,8 +26,8 @@ #include "srslte/srslte.h" -#ifndef SCHED_INTERFACE_H -#define SCHED_INTERFACE_H +#ifndef SRSLTE_SCHED_INTERFACE_H +#define SRSLTE_SCHED_INTERFACE_H namespace srsenb { @@ -248,4 +248,4 @@ public: } -#endif +#endif // SRSLTE_SCHED_INTERFACE_H diff --git a/lib/include/srslte/interfaces/ue_interfaces.h b/lib/include/srslte/interfaces/ue_interfaces.h index bea0cb05c..b1c0672d3 100644 --- a/lib/include/srslte/interfaces/ue_interfaces.h +++ b/lib/include/srslte/interfaces/ue_interfaces.h @@ -30,8 +30,8 @@ * to other layers. *****************************************************************************/ -#ifndef INTERFACES_H -#define INTERFACES_H +#ifndef SRSLTE_UE_INTERFACES_H +#define SRSLTE_UE_INTERFACES_H #include @@ -599,6 +599,6 @@ public: }; -} // namespace srslte +} // namespace srsue -#endif // INTERFACES_H +#endif // SRSLTE_UE_INTERFACES_H diff --git a/lib/include/srslte/phy/agc/agc.h b/lib/include/srslte/phy/agc/agc.h index 0a6bba8c1..ab7bb2ed7 100644 --- a/lib/include/srslte/phy/agc/agc.h +++ b/lib/include/srslte/phy/agc/agc.h @@ -33,8 +33,8 @@ * Reference: *********************************************************************************************/ -#ifndef AGC_ -#define AGC_ +#ifndef SRSLTE_AGC_H +#define SRSLTE_AGC_H #include #include @@ -101,4 +101,4 @@ SRSLTE_API void srslte_agc_process(srslte_agc_t *q, cf_t *signal, uint32_t len); -#endif // AGC_ +#endif // SRSLTE_AGC_H diff --git a/lib/include/srslte/phy/ch_estimation/chest_common.h b/lib/include/srslte/phy/ch_estimation/chest_common.h index 8eb63aa73..276d9c55e 100644 --- a/lib/include/srslte/phy/ch_estimation/chest_common.h +++ b/lib/include/srslte/phy/ch_estimation/chest_common.h @@ -24,8 +24,8 @@ * */ -#ifndef CHEST_ -#define CHEST_ +#ifndef SRSLTE_CHEST_COMMON_H +#define SRSLTE_CHEST_COMMON_H #include #include "srslte/config.h" @@ -51,5 +51,5 @@ SRSLTE_API float srslte_chest_estimate_noise_pilots(cf_t *noisy, SRSLTE_API void srslte_chest_set_triangle_filter(float *fil, int filter_len); -#endif +#endif // SRSLTE_CHEST_COMMON_H diff --git a/lib/include/srslte/phy/ch_estimation/chest_dl.h b/lib/include/srslte/phy/ch_estimation/chest_dl.h index e7cc28bed..a521d653e 100644 --- a/lib/include/srslte/phy/ch_estimation/chest_dl.h +++ b/lib/include/srslte/phy/ch_estimation/chest_dl.h @@ -38,8 +38,8 @@ * Reference: *********************************************************************************************/ -#ifndef CHEST_DL_ -#define CHEST_DL_ +#ifndef SRSLTE_CHEST_DL_H +#define SRSLTE_CHEST_DL_H #include @@ -193,4 +193,4 @@ SRSLTE_API float srslte_chest_dl_get_rsrp(srslte_chest_dl_t *q); SRSLTE_API float srslte_chest_dl_get_rsrp_neighbour(srslte_chest_dl_t *q); -#endif +#endif // SRSLTE_CHEST_DL_H diff --git a/lib/include/srslte/phy/ch_estimation/chest_ul.h b/lib/include/srslte/phy/ch_estimation/chest_ul.h index 0571fec8c..df5c11db6 100644 --- a/lib/include/srslte/phy/ch_estimation/chest_ul.h +++ b/lib/include/srslte/phy/ch_estimation/chest_ul.h @@ -36,8 +36,8 @@ * Reference: *********************************************************************************************/ -#ifndef CHEST_UL_ -#define CHEST_UL_ +#ifndef SRSLTE_CHEST_UL_H +#define SRSLTE_CHEST_UL_H #include @@ -118,4 +118,4 @@ SRSLTE_API float srslte_chest_ul_get_noise_estimate(srslte_chest_ul_t *q); SRSLTE_API float srslte_chest_ul_get_snr(srslte_chest_ul_t *q); -#endif +#endif // SRSLTE_CHEST_UL_H diff --git a/lib/include/srslte/phy/ch_estimation/refsignal_dl.h b/lib/include/srslte/phy/ch_estimation/refsignal_dl.h index 9263073a9..6167d8d4e 100644 --- a/lib/include/srslte/phy/ch_estimation/refsignal_dl.h +++ b/lib/include/srslte/phy/ch_estimation/refsignal_dl.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.10 *********************************************************************************************/ -#ifndef SRSLTE_REFSIGNAL_DL_ -#define SRSLTE_REFSIGNAL_DL_ +#ifndef SRSLTE_REFSIGNAL_DL_H +#define SRSLTE_REFSIGNAL_DL_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -118,4 +118,4 @@ SRSLTE_API int srslte_refsignal_mbsfn_gen_seq(srslte_refsignal_t * q, uint32_t N_mbsfn_id); -#endif +#endif // SRSLTE_REFSIGNAL_DL_H diff --git a/lib/include/srslte/phy/ch_estimation/refsignal_ul.h b/lib/include/srslte/phy/ch_estimation/refsignal_ul.h index 9e1da9e50..7b393e8d9 100644 --- a/lib/include/srslte/phy/ch_estimation/refsignal_ul.h +++ b/lib/include/srslte/phy/ch_estimation/refsignal_ul.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 5.5 *********************************************************************************************/ -#ifndef SRSLTE_REFSIGNAL_UL_ -#define SRSLTE_REFSIGNAL_UL_ +#ifndef SRSLTE_REFSIGNAL_UL_H +#define SRSLTE_REFSIGNAL_UL_H #include "srslte/config.h" #include "srslte/phy/phch/pucch.h" @@ -209,4 +209,4 @@ SRSLTE_API uint32_t srslte_refsignal_srs_rb_L_cs(uint32_t bw_cfg, SRSLTE_API uint32_t srslte_refsignal_srs_M_sc(srslte_refsignal_ul_t *q); -#endif +#endif // SRSLTE_REFSIGNAL_UL_H diff --git a/lib/include/srslte/phy/channel/ch_awgn.h b/lib/include/srslte/phy/channel/ch_awgn.h index ace971961..3dbabcda7 100644 --- a/lib/include/srslte/phy/channel/ch_awgn.h +++ b/lib/include/srslte/phy/channel/ch_awgn.h @@ -37,8 +37,8 @@ #include "srslte/config.h" -#ifndef CH_AWGN_ -#define CH_AWGN_ +#ifndef SRSLTE_CH_AWGN_H +#define SRSLTE_CH_AWGN_H SRSLTE_API void srslte_ch_awgn_c(const cf_t* input, cf_t* output, @@ -54,4 +54,4 @@ SRSLTE_API float srslte_ch_awgn_get_variance(float ebno_db, float rate); -#endif +#endif // SRSLTE_CH_AWGN_H diff --git a/lib/include/srslte/phy/common/phy_common.h b/lib/include/srslte/phy/common/phy_common.h index c55713cfc..82c2dfaa8 100644 --- a/lib/include/srslte/phy/common/phy_common.h +++ b/lib/include/srslte/phy/common/phy_common.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 *********************************************************************************************/ -#ifndef _LTEBASE_ -#define _LTEBASE_ +#ifndef SRSLTE_PHY_COMMON_H +#define SRSLTE_PHY_COMMON_H #include #include @@ -305,4 +305,4 @@ SRSLTE_API char *srslte_mimotype2str(srslte_mimo_type_t mimo_type); SRSLTE_API uint32_t srslte_tti_interval(uint32_t tti1, uint32_t tti2); -#endif +#endif // SRSLTE_PHY_COMMON_H diff --git a/lib/include/srslte/phy/common/phy_logger.h b/lib/include/srslte/phy/common/phy_logger.h index d02efbb47..2f0805df8 100644 --- a/lib/include/srslte/phy/common/phy_logger.h +++ b/lib/include/srslte/phy/common/phy_logger.h @@ -29,8 +29,8 @@ * Description: Interface for logging output *****************************************************************************/ -#ifndef PHY_LOGGER_H -#define PHY_LOGGER_H +#ifndef SRSLTE_PHY_LOGGER_H +#define SRSLTE_PHY_LOGGER_H #include #include @@ -56,4 +56,4 @@ void srslte_phy_log_register_handler(void *ctx, phy_log_handler_t handler); } #endif // C++ -#endif // LOGGER_H +#endif // SRSLTE_PHY_LOGGER_H diff --git a/lib/include/srslte/phy/common/sequence.h b/lib/include/srslte/phy/common/sequence.h index 62934c7e0..346be1cda 100644 --- a/lib/include/srslte/phy/common/sequence.h +++ b/lib/include/srslte/phy/common/sequence.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 7.2 *********************************************************************************************/ -#ifndef LTESEQ_ -#define LTESEQ_ +#ifndef SRSLTE_SEQUENCE_H +#define SRSLTE_SEQUENCE_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -100,4 +100,4 @@ SRSLTE_API int srslte_sequence_pmch(srslte_sequence_t *seq, uint32_t mbsfn_id, uint32_t len); -#endif +#endif // SRSLTE_SEQUENCE_H diff --git a/lib/include/srslte/phy/common/timestamp.h b/lib/include/srslte/phy/common/timestamp.h index 8dd960b69..f4c505b4a 100644 --- a/lib/include/srslte/phy/common/timestamp.h +++ b/lib/include/srslte/phy/common/timestamp.h @@ -34,8 +34,8 @@ * Reference: *********************************************************************************************/ -#ifndef TIMESTAMP_ -#define TIMESTAMP_ +#ifndef SRSLTE_TIMESTAMP_H +#define SRSLTE_TIMESTAMP_H #include #include @@ -65,4 +65,4 @@ SRSLTE_API double srslte_timestamp_real(srslte_timestamp_t *t); SRSLTE_API uint32_t srslte_timestamp_uint32(srslte_timestamp_t *t); -#endif // TIMESTAMP_ +#endif // SRSLTE_TIMESTAMP_H diff --git a/lib/include/srslte/phy/dft/dft.h b/lib/include/srslte/phy/dft/dft.h index afe8024d2..e62362d8c 100644 --- a/lib/include/srslte/phy/dft/dft.h +++ b/lib/include/srslte/phy/dft/dft.h @@ -25,8 +25,8 @@ */ -#ifndef DFT_H_ -#define DFT_H_ +#ifndef SRSLTE_DFT_H +#define SRSLTE_DFT_H #include #include "srslte/config.h" @@ -157,5 +157,5 @@ SRSLTE_API void srslte_dft_run_r(srslte_dft_plan_t *plan, const float *in, float *out); -#endif // DFT_H_ +#endif // SRSLTE_DFT_H diff --git a/lib/include/srslte/phy/dft/dft_precoding.h b/lib/include/srslte/phy/dft/dft_precoding.h index 022593aa7..c1eb20ec6 100644 --- a/lib/include/srslte/phy/dft/dft_precoding.h +++ b/lib/include/srslte/phy/dft/dft_precoding.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 5.3.3 *********************************************************************************************/ -#ifndef DFTPREC_ -#define DFTPREC_ +#ifndef SRSLTE_DFT_PRECODING_H +#define SRSLTE_DFT_PRECODING_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -68,4 +68,4 @@ SRSLTE_API int srslte_dft_precoding(srslte_dft_precoding_t *q, uint32_t nof_prb, uint32_t nof_symbols); -#endif +#endif // SRSLTE_DFT_PRECODING_H diff --git a/lib/include/srslte/phy/dft/ofdm.h b/lib/include/srslte/phy/dft/ofdm.h index e48c240b9..6f31ed3ab 100644 --- a/lib/include/srslte/phy/dft/ofdm.h +++ b/lib/include/srslte/phy/dft/ofdm.h @@ -25,8 +25,8 @@ */ -#ifndef LTEFFT_ -#define LTEFFT_ +#ifndef SRSLTE_OFDM_H +#define SRSLTE_OFDM_H /********************************************************************************************** * File: ofdm.h @@ -158,4 +158,4 @@ SRSLTE_API void srslte_ofdm_set_non_mbsfn_region(srslte_ofdm_t *q, uint8_t non_mbsfn_region); -#endif +#endif // SRSLTE_OFDM_H diff --git a/lib/include/srslte/phy/enb/enb_dl.h b/lib/include/srslte/phy/enb/enb_dl.h index 232dc459c..2b11bd6e3 100644 --- a/lib/include/srslte/phy/enb/enb_dl.h +++ b/lib/include/srslte/phy/enb/enb_dl.h @@ -35,8 +35,8 @@ * Reference: *****************************************************************************/ -#ifndef ENBDL_H -#define ENBDL_H +#ifndef SRSLTE_ENB_DL_H +#define SRSLTE_ENB_DL_H #include @@ -195,4 +195,4 @@ SRSLTE_API void srslte_enb_dl_save_signal(srslte_enb_dl_t *q, uint16_t rnti, uint32_t cfi); -#endif +#endif // SRSLTE_ENB_DL_H diff --git a/lib/include/srslte/phy/enb/enb_ul.h b/lib/include/srslte/phy/enb/enb_ul.h index 8699a2a37..49d174807 100644 --- a/lib/include/srslte/phy/enb/enb_ul.h +++ b/lib/include/srslte/phy/enb/enb_ul.h @@ -35,8 +35,8 @@ * Reference: *****************************************************************************/ -#ifndef ENBUL_H -#define ENBUL_H +#ifndef SRSLTE_ENB_UL_H +#define SRSLTE_ENB_UL_H #include @@ -153,4 +153,4 @@ SRSLTE_API int srslte_enb_ul_detect_prach(srslte_enb_ul_t *q, float *peak2avg); -#endif +#endif // SRSLTE_ENB_UL_H diff --git a/lib/include/srslte/phy/fec/cbsegm.h b/lib/include/srslte/phy/fec/cbsegm.h index f89cb089d..7eee8320d 100644 --- a/lib/include/srslte/phy/fec/cbsegm.h +++ b/lib/include/srslte/phy/fec/cbsegm.h @@ -29,8 +29,8 @@ #include "srslte/config.h" -#ifndef CBSEGM_H -#define CBSEGM_H +#ifndef SRSLTE_CBSEGM_H +#define SRSLTE_CBSEGM_H #define SRSLTE_NOF_TC_CB_SIZES 188 @@ -56,4 +56,4 @@ SRSLTE_API bool srslte_cbsegm_cbsize_isvalid(uint32_t size); SRSLTE_API int srslte_cbsegm_cbindex(uint32_t long_cb); -#endif +#endif // SRSLTE_CBSEGM_H diff --git a/lib/include/srslte/phy/fec/convcoder.h b/lib/include/srslte/phy/fec/convcoder.h index 1d51cbcbc..99dfd333e 100644 --- a/lib/include/srslte/phy/fec/convcoder.h +++ b/lib/include/srslte/phy/fec/convcoder.h @@ -34,8 +34,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.1 *********************************************************************************************/ -#ifndef CONVCODER_ -#define CONVCODER_ +#ifndef SRSLTE_CONVCODER_H +#define SRSLTE_CONVCODER_H #include #include "srslte/config.h" @@ -53,4 +53,4 @@ SRSLTE_API int srslte_convcoder_encode(srslte_convcoder_t *q, uint32_t frame_length); -#endif +#endif // SRSLTE_CONVCODER_H diff --git a/lib/include/srslte/phy/fec/crc.h b/lib/include/srslte/phy/fec/crc.h index 89b4a122f..030e7c6bb 100644 --- a/lib/include/srslte/phy/fec/crc.h +++ b/lib/include/srslte/phy/fec/crc.h @@ -34,8 +34,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.1 *********************************************************************************************/ -#ifndef CRC_ -#define CRC_ +#ifndef SRSLTE_CRC_H +#define SRSLTE_CRC_H #include "srslte/config.h" #include @@ -73,4 +73,4 @@ SRSLTE_API uint32_t srslte_crc_checksum(srslte_crc_t *h, uint8_t *data, int len); -#endif +#endif // SRSLTE_CRC_H diff --git a/lib/include/srslte/phy/fec/rm_conv.h b/lib/include/srslte/phy/fec/rm_conv.h index 92e640e3a..9681ce827 100644 --- a/lib/include/srslte/phy/fec/rm_conv.h +++ b/lib/include/srslte/phy/fec/rm_conv.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.4.2 *********************************************************************************************/ -#ifndef RM_CONV_ -#define RM_CONV_ +#ifndef SRSLTE_RM_CONV_H +#define SRSLTE_RM_CONV_H #include "srslte/config.h" @@ -63,4 +63,4 @@ SRSLTE_API int srslte_rm_conv_rx_s(int16_t *input, int16_t *output, uint32_t out_len); -#endif +#endif // SRSLTE_RM_CONV_H diff --git a/lib/include/srslte/phy/fec/rm_turbo.h b/lib/include/srslte/phy/fec/rm_turbo.h index 182b49fb8..26f98944c 100644 --- a/lib/include/srslte/phy/fec/rm_turbo.h +++ b/lib/include/srslte/phy/fec/rm_turbo.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.4.1 *********************************************************************************************/ -#ifndef RM_TURBO_ -#define RM_TURBO_ +#ifndef SRSLTE_RM_TURBO_H +#define SRSLTE_RM_TURBO_H #include "srslte/config.h" @@ -85,4 +85,4 @@ SRSLTE_API int srslte_rm_turbo_rx_lut(int16_t *input, uint32_t rv_idx); -#endif +#endif // SRSLTE_RM_TURBO_H diff --git a/lib/include/srslte/phy/fec/softbuffer.h b/lib/include/srslte/phy/fec/softbuffer.h index 3949134d8..864fc1439 100644 --- a/lib/include/srslte/phy/fec/softbuffer.h +++ b/lib/include/srslte/phy/fec/softbuffer.h @@ -33,8 +33,8 @@ * Reference: *****************************************************************************/ -#ifndef SOFTBUFFER_ -#define SOFTBUFFER_ +#ifndef SRSLTE_SOFTBUFFER_H +#define SRSLTE_SOFTBUFFER_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -82,4 +82,4 @@ SRSLTE_API void srslte_softbuffer_tx_free(srslte_softbuffer_tx_t *p); -#endif +#endif // SRSLTE_SOFTBUFFER_H diff --git a/lib/include/srslte/phy/fec/tc_interl.h b/lib/include/srslte/phy/fec/tc_interl.h index ad46edd8f..c0ffaae58 100644 --- a/lib/include/srslte/phy/fec/tc_interl.h +++ b/lib/include/srslte/phy/fec/tc_interl.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.2.3 *********************************************************************************************/ -#ifndef _TC_INTERL_H -#define _TC_INTERL_H +#ifndef SRSLTE_TC_INTERL_H +#define SRSLTE_TC_INTERL_H #include "srslte/config.h" #include @@ -55,4 +55,4 @@ SRSLTE_API int srslte_tc_interl_init(srslte_tc_interl_t *h, SRSLTE_API void srslte_tc_interl_free(srslte_tc_interl_t *h); -#endif +#endif // SRSLTE_TC_INTERL_H diff --git a/lib/include/srslte/phy/fec/turbocoder.h b/lib/include/srslte/phy/fec/turbocoder.h index 119e4f641..485e83ff3 100644 --- a/lib/include/srslte/phy/fec/turbocoder.h +++ b/lib/include/srslte/phy/fec/turbocoder.h @@ -35,8 +35,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.2 *********************************************************************************************/ -#ifndef TURBOCODER_ -#define TURBOCODER_ +#ifndef SRSLTE_TURBOCODER_H +#define SRSLTE_TURBOCODER_H #include "srslte/config.h" #include "srslte/phy/fec/tc_interl.h" @@ -75,5 +75,5 @@ SRSLTE_API int srslte_tcod_encode_lut(srslte_tcod_t *h, SRSLTE_API void srslte_tcod_gentable(); -#endif +#endif // SRSLTE_TURBOCODER_H diff --git a/lib/include/srslte/phy/fec/turbodecoder.h b/lib/include/srslte/phy/fec/turbodecoder.h index ac05422bc..d882118aa 100644 --- a/lib/include/srslte/phy/fec/turbodecoder.h +++ b/lib/include/srslte/phy/fec/turbodecoder.h @@ -36,8 +36,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.2 *********************************************************************************************/ -#ifndef TURBODECODER_ -#define TURBODECODER_ +#ifndef SRSLTE_TURBODECODER_H +#define SRSLTE_TURBODECODER_H #include "srslte/config.h" #include "srslte/phy/fec/tc_interl.h" @@ -117,4 +117,4 @@ SRSLTE_API int srslte_tdec_run_all_par(srslte_tdec_t * h, uint32_t nof_iterations, uint32_t long_cb); -#endif +#endif // SRSLTE_TURBODECODER_H diff --git a/lib/include/srslte/phy/fec/turbodecoder_gen.h b/lib/include/srslte/phy/fec/turbodecoder_gen.h index 4a023396c..2fefc22cc 100644 --- a/lib/include/srslte/phy/fec/turbodecoder_gen.h +++ b/lib/include/srslte/phy/fec/turbodecoder_gen.h @@ -36,8 +36,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.2 *********************************************************************************************/ -#ifndef TURBODECODER_GEN_ -#define TURBODECODER_GEN_ +#ifndef SRSLTE_TURBODECODER_GEN_H +#define SRSLTE_TURBODECODER_GEN_H #include "srslte/config.h" #include "srslte/phy/fec/tc_interl.h" @@ -96,4 +96,4 @@ SRSLTE_API int srslte_tdec_gen_run_all(srslte_tdec_gen_t * h, uint32_t nof_iterations, uint32_t long_cb); -#endif +#endif // SRSLTE_TURBODECODER_GEN_H diff --git a/lib/include/srslte/phy/fec/turbodecoder_simd.h b/lib/include/srslte/phy/fec/turbodecoder_simd.h index a899a5964..35c8beef9 100644 --- a/lib/include/srslte/phy/fec/turbodecoder_simd.h +++ b/lib/include/srslte/phy/fec/turbodecoder_simd.h @@ -36,8 +36,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.2 *********************************************************************************************/ -#ifndef TURBODECODER_SSE_ -#define TURBODECODER_SSE_ +#ifndef SRSLTE_TURBODECODER_SIMD_H +#define SRSLTE_TURBODECODER_SIMD_H #include "srslte/config.h" #include "srslte/phy/fec/tc_interl.h" @@ -119,4 +119,4 @@ SRSLTE_API int srslte_tdec_simd_run_all(srslte_tdec_simd_t * h, uint32_t nof_iterations, uint32_t long_cb); -#endif +#endif // SRSLTE_TURBODECODER_SIMD_H diff --git a/lib/include/srslte/phy/fec/turbodecoder_simd_inter.h b/lib/include/srslte/phy/fec/turbodecoder_simd_inter.h index c80785809..054fbc3cb 100644 --- a/lib/include/srslte/phy/fec/turbodecoder_simd_inter.h +++ b/lib/include/srslte/phy/fec/turbodecoder_simd_inter.h @@ -36,8 +36,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.2 *********************************************************************************************/ -#ifndef TURBODECODER_SSE_INTER_ -#define TURBODECODER_SSE_INTER_ +#ifndef SRSLTE_TURBODECODER_SIMD_INTER_H +#define SRSLTE_TURBODECODER_SIMD_INTER_H /** This is an simd inter-frame parallel turbo decoder. Parallizes 8 code-blocks using SSE @@ -116,4 +116,4 @@ SRSLTE_API int srslte_tdec_simd_inter_run_all(srslte_tdec_simd_inter_t * h, uint32_t nof_cb, uint32_t long_cb); -#endif +#endif // SRSLTE_TURBODECODER_SIMD_INTER_H diff --git a/lib/include/srslte/phy/fec/turbodecoder_sse.h b/lib/include/srslte/phy/fec/turbodecoder_sse.h index 8b9f24372..9678fba9a 100644 --- a/lib/include/srslte/phy/fec/turbodecoder_sse.h +++ b/lib/include/srslte/phy/fec/turbodecoder_sse.h @@ -36,8 +36,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.1.3.2 *********************************************************************************************/ -#ifndef TURBODECODER_SSE_ -#define TURBODECODER_SSE_ +#ifndef SRSLTE_TURBODECODER_SSE_ +#define SRSLTE_TURBODECODER_SSE_ #include "srslte/config.h" #include "srslte/phy/fec/tc_interl.h" @@ -98,4 +98,4 @@ SRSLTE_API int srslte_tdec_sse_run_all(srslte_tdec_sse_t * h, uint32_t nof_iterations, uint32_t long_cb); -#endif +#endif // SRSLTE_TURBODECODER_SSE_ diff --git a/lib/include/srslte/phy/fec/viterbi.h b/lib/include/srslte/phy/fec/viterbi.h index 689b636e9..0f6f0cd50 100644 --- a/lib/include/srslte/phy/fec/viterbi.h +++ b/lib/include/srslte/phy/fec/viterbi.h @@ -33,8 +33,8 @@ * Reference: *****************************************************************************/ -#ifndef VITERBI_ -#define VITERBI_ +#ifndef SRSLTE_VITERBI_H +#define SRSLTE_VITERBI_H #include #include "srslte/config.h" @@ -119,4 +119,4 @@ SRSLTE_API int srslte_viterbi_init_avx2(srslte_viterbi_t *q, -#endif +#endif // SRSLTE_VITERBI_H diff --git a/lib/include/srslte/phy/io/binsource.h b/lib/include/srslte/phy/io/binsource.h index a89a305ea..733449b25 100644 --- a/lib/include/srslte/phy/io/binsource.h +++ b/lib/include/srslte/phy/io/binsource.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef BINSOURCE_ -#define BINSOURCE_ +#ifndef SRSLTE_BINSOURCE_H +#define SRSLTE_BINSOURCE_H #include @@ -68,4 +68,4 @@ SRSLTE_API int srslte_binsource_generate(srslte_binsource_t* q, uint8_t *bits, int nbits); -#endif // BINSOURCE_ +#endif // SRSLTE_BINSOURCE_H diff --git a/lib/include/srslte/phy/io/filesink.h b/lib/include/srslte/phy/io/filesink.h index 921f1e440..b6fee3adf 100644 --- a/lib/include/srslte/phy/io/filesink.h +++ b/lib/include/srslte/phy/io/filesink.h @@ -34,8 +34,8 @@ * Reference: *****************************************************************************/ -#ifndef FILESINK_ -#define FILESINK_ +#ifndef SRSLTE_FILESINK_H +#define SRSLTE_FILESINK_H #include #include @@ -64,4 +64,4 @@ SRSLTE_API int srslte_filesink_write_multi(srslte_filesink_t *q, int nsamples, int nchannels); -#endif // FILESINK_ +#endif // SRSLTE_FILESINK_H diff --git a/lib/include/srslte/phy/io/filesource.h b/lib/include/srslte/phy/io/filesource.h index f515d7034..d4ad81f94 100644 --- a/lib/include/srslte/phy/io/filesource.h +++ b/lib/include/srslte/phy/io/filesource.h @@ -34,8 +34,8 @@ * Reference: *****************************************************************************/ -#ifndef FILESOURCE_ -#define FILESOURCE_ +#ifndef SRSLTE_FILESOURCE_H +#define SRSLTE_FILESOURCE_H #include #include @@ -67,4 +67,4 @@ SRSLTE_API int srslte_filesource_read_multi(srslte_filesource_t *q, int nsamples, int nof_channels); -#endif // FILESOURCE_ +#endif // SRSLTE_FILESOURCE_H diff --git a/lib/include/srslte/phy/io/format.h b/lib/include/srslte/phy/io/format.h index 81bf1f702..22c0e3973 100644 --- a/lib/include/srslte/phy/io/format.h +++ b/lib/include/srslte/phy/io/format.h @@ -25,8 +25,8 @@ */ -#ifndef FORMAT_ -#define FORMAT_ +#ifndef SRSLTE_FORMAT_H +#define SRSLTE_FORMAT_H typedef enum { SRSLTE_FLOAT, @@ -37,4 +37,4 @@ typedef enum { SRSLTE_COMPLEX_SHORT_BIN } srslte_datatype_t; -#endif // FORMAT_ +#endif // SRSLTE_FORMAT_H diff --git a/lib/include/srslte/phy/io/netsink.h b/lib/include/srslte/phy/io/netsink.h index 3339716c1..246c520bf 100644 --- a/lib/include/srslte/phy/io/netsink.h +++ b/lib/include/srslte/phy/io/netsink.h @@ -33,8 +33,8 @@ * Reference: *****************************************************************************/ -#ifndef NETSINK_ -#define NETSINK_ +#ifndef SRSLTE_NETSINK_H +#define SRSLTE_NETSINK_H #include #include @@ -71,4 +71,4 @@ SRSLTE_API int srslte_netsink_write(srslte_netsink_t *q, SRSLTE_API int srslte_netsink_set_nonblocking(srslte_netsink_t *q); -#endif // UDPSINK_ +#endif // SRSLTE_NETSINK_H diff --git a/lib/include/srslte/phy/io/netsource.h b/lib/include/srslte/phy/io/netsource.h index e10d8d644..ee0ca69da 100644 --- a/lib/include/srslte/phy/io/netsource.h +++ b/lib/include/srslte/phy/io/netsource.h @@ -33,8 +33,8 @@ * Reference: *****************************************************************************/ -#ifndef NETSOURCE_ -#define NETSOURCE_ +#ifndef SRSLTE_NETSOURCE_H +#define SRSLTE_NETSOURCE_H #include #include @@ -75,4 +75,4 @@ SRSLTE_API int srslte_netsource_read(srslte_netsource_t *q, SRSLTE_API int srslte_netsource_set_timeout(srslte_netsource_t *q, uint32_t microseconds); -#endif // UDPSOURCE_ +#endif // SRSLTE_NETSOURCE_H diff --git a/lib/include/srslte/phy/mimo/layermap.h b/lib/include/srslte/phy/mimo/layermap.h index 5daf51c14..d6328a7ad 100644 --- a/lib/include/srslte/phy/mimo/layermap.h +++ b/lib/include/srslte/phy/mimo/layermap.h @@ -34,8 +34,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.3.3 *****************************************************************************/ -#ifndef LAYERMAP_H_ -#define LAYERMAP_H_ +#ifndef SRSLTE_LAYERMAP_H +#define SRSLTE_LAYERMAP_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -91,4 +91,4 @@ SRSLTE_API int srslte_layerdemap_type(cf_t *x[SRSLTE_MAX_LAYERS], int nof_symbols[SRSLTE_MAX_CODEWORDS], srslte_mimo_type_t type); -#endif // LAYERMAP_H_ +#endif // SRSLTE_LAYERMAP_H diff --git a/lib/include/srslte/phy/mimo/precoding.h b/lib/include/srslte/phy/mimo/precoding.h index 27395085c..d363231e2 100644 --- a/lib/include/srslte/phy/mimo/precoding.h +++ b/lib/include/srslte/phy/mimo/precoding.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.3.4 *****************************************************************************/ -#ifndef PRECODING_H_ -#define PRECODING_H_ +#ifndef SRSLTE_PRECODING_H +#define SRSLTE_PRECODING_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -137,4 +137,4 @@ SRSLTE_API int srslte_precoding_cn(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], float *cn); -#endif /* PRECODING_H_ */ +#endif // SRSLTE_PRECODING_H diff --git a/lib/include/srslte/phy/modem/demod_hard.h b/lib/include/srslte/phy/modem/demod_hard.h index 6da2b7b4d..689bcca42 100644 --- a/lib/include/srslte/phy/modem/demod_hard.h +++ b/lib/include/srslte/phy/modem/demod_hard.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 7.1 *****************************************************************************/ -#ifndef DEMOD_HARD_ -#define DEMOD_HARD_ +#ifndef SRSLTE_DEMOD_HARD_H +#define SRSLTE_DEMOD_HARD_H #include #include @@ -57,4 +57,4 @@ SRSLTE_API int srslte_demod_hard_demodulate(srslte_demod_hard_t* q, uint8_t *bits, uint32_t nsymbols); -#endif // DEMOD_HARD_ +#endif // SRSLTE_DEMOD_HARD_H diff --git a/lib/include/srslte/phy/modem/demod_soft.h b/lib/include/srslte/phy/modem/demod_soft.h index 7ac4f0702..9ad065edc 100644 --- a/lib/include/srslte/phy/modem/demod_soft.h +++ b/lib/include/srslte/phy/modem/demod_soft.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 7.1 *****************************************************************************/ -#ifndef DEMOD_SOFT_ -#define DEMOD_SOFT_ +#ifndef SRSLTE_DEMOD_SOFT_H +#define SRSLTE_DEMOD_SOFT_H #include #include @@ -53,4 +53,4 @@ SRSLTE_API int srslte_demod_soft_demodulate_s(srslte_mod_t modulation, short* llr, int nsymbols); -#endif // DEMOD_SOFT_ +#endif // SRSLTE_DEMOD_SOFT_H diff --git a/lib/include/srslte/phy/modem/mod.h b/lib/include/srslte/phy/modem/mod.h index 66aa997cb..a2f8299a1 100644 --- a/lib/include/srslte/phy/modem/mod.h +++ b/lib/include/srslte/phy/modem/mod.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 7.1 *****************************************************************************/ -#ifndef MOD_ -#define MOD_ +#ifndef SRSLTE_MOD_H +#define SRSLTE_MOD_H #include #include @@ -52,4 +52,4 @@ SRSLTE_API int srslte_mod_modulate_bytes(srslte_modem_table_t* q, cf_t* symbols, uint32_t nbits); -#endif // MOD_ +#endif // SRSLTE_MOD_H diff --git a/lib/include/srslte/phy/modem/modem_table.h b/lib/include/srslte/phy/modem/modem_table.h index 20b0a0f88..09cea5e10 100644 --- a/lib/include/srslte/phy/modem/modem_table.h +++ b/lib/include/srslte/phy/modem/modem_table.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 7.1 *****************************************************************************/ -#ifndef MODEM_TABLE_ -#define MODEM_TABLE_ +#ifndef SRSLTE_MODEM_TABLE_H +#define SRSLTE_MODEM_TABLE_H #include #include @@ -83,4 +83,4 @@ SRSLTE_API int srslte_modem_table_lte(srslte_modem_table_t* q, SRSLTE_API void srslte_modem_table_bytes(srslte_modem_table_t* q); -#endif // MODEM_TABLE_ +#endif // SRSLTE_MODEM_TABLE_H diff --git a/lib/include/srslte/phy/phch/cqi.h b/lib/include/srslte/phy/phch/cqi.h index b8cc80ece..4363ccaa7 100644 --- a/lib/include/srslte/phy/phch/cqi.h +++ b/lib/include/srslte/phy/phch/cqi.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.2.2.6, 5.2.3.3 *****************************************************************************/ -#ifndef CQI_ -#define CQI_ +#ifndef SRSLTE_CQI_H +#define SRSLTE_CQI_H #include @@ -179,4 +179,4 @@ SRSLTE_API int srslte_cqi_hl_get_no_subbands(int num_prbs); SRSLTE_API void srslte_cqi_to_str(const uint8_t *cqi_value, int cqi_len, char *str, int str_len); -#endif // CQI_ +#endif // SRSLTE_CQI_H diff --git a/lib/include/srslte/phy/phch/dci.h b/lib/include/srslte/phy/phch/dci.h index 79a79c4df..1a7bfbb0f 100644 --- a/lib/include/srslte/phy/phch/dci.h +++ b/lib/include/srslte/phy/phch/dci.h @@ -34,8 +34,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.3.3 *****************************************************************************/ -#ifndef DCI_ -#define DCI_ +#ifndef SRSLTE_DCI_H +#define SRSLTE_DCI_H #include diff --git a/lib/include/srslte/phy/phch/pbch.h b/lib/include/srslte/phy/phch/pbch.h index 4dc7ec727..1e0af67cd 100644 --- a/lib/include/srslte/phy/phch/pbch.h +++ b/lib/include/srslte/phy/phch/pbch.h @@ -34,8 +34,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.6 *****************************************************************************/ -#ifndef PBCH_ -#define PBCH_ +#ifndef SRSLTE_PBCH_H +#define SRSLTE_PBCH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -115,4 +115,4 @@ SRSLTE_API void srslte_pbch_mib_pack(srslte_cell_t *cell, uint32_t sfn, uint8_t *msg); -#endif // PBCH_ +#endif // SRSLTE_PBCH_H diff --git a/lib/include/srslte/phy/phch/pcfich.h b/lib/include/srslte/phy/phch/pcfich.h index fbbb82c88..554a150a7 100644 --- a/lib/include/srslte/phy/phch/pcfich.h +++ b/lib/include/srslte/phy/phch/pcfich.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.7 *****************************************************************************/ -#ifndef PCFICH_ -#define PCFICH_ +#ifndef SRSLTE_PCFICH_H +#define SRSLTE_PCFICH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -108,4 +108,4 @@ SRSLTE_API int srslte_pcfich_encode(srslte_pcfich_t *q, cf_t *sf_symbols[SRSLTE_MAX_PORTS], uint32_t subframe); -#endif +#endif // SRSLTE_PCFICH_H diff --git a/lib/include/srslte/phy/phch/pdcch.h b/lib/include/srslte/phy/phch/pdcch.h index 423204996..14f7b07ab 100644 --- a/lib/include/srslte/phy/phch/pdcch.h +++ b/lib/include/srslte/phy/phch/pdcch.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.8 *****************************************************************************/ -#ifndef PDCCH_ -#define PDCCH_ +#ifndef SRSLTE_PDCCH_H +#define SRSLTE_PDCCH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -186,4 +186,4 @@ SRSLTE_API uint32_t srslte_pdcch_common_locations_ncce(uint32_t nof_cce, uint32_t max_candidates); -#endif +#endif // SRSLTE_PDCCH_H diff --git a/lib/include/srslte/phy/phch/pdsch.h b/lib/include/srslte/phy/phch/pdsch.h index 1889078e6..8a733c992 100644 --- a/lib/include/srslte/phy/phch/pdsch.h +++ b/lib/include/srslte/phy/phch/pdsch.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.4 *****************************************************************************/ -#ifndef PDSCH_ -#define PDSCH_ +#ifndef SRSLTE_PDSCH_H +#define SRSLTE_PDSCH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -170,4 +170,4 @@ SRSLTE_API float srslte_pdsch_last_noi(srslte_pdsch_t *q); SRSLTE_API uint32_t srslte_pdsch_last_noi_cw(srslte_pdsch_t *q, uint32_t cw_idx); -#endif +#endif // SRSLTE_PDSCH_H diff --git a/lib/include/srslte/phy/phch/pdsch_cfg.h b/lib/include/srslte/phy/phch/pdsch_cfg.h index 569d1ef7e..3e4849014 100644 --- a/lib/include/srslte/phy/phch/pdsch_cfg.h +++ b/lib/include/srslte/phy/phch/pdsch_cfg.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.4 *****************************************************************************/ -#ifndef PDSCHCFG_ -#define PDSCHCFG_ +#ifndef SRSLTE_PDSCH_CFG_H +#define SRSLTE_PDSCH_CFG_H #include "srslte/phy/phch/ra.h" #include "srslte/phy/fec/softbuffer.h" @@ -58,5 +58,5 @@ typedef struct SRSLTE_API { bool tb_cw_swap; } srslte_pdsch_cfg_t; -#endif +#endif // SRSLTE_PDSCH_CFG_H diff --git a/lib/include/srslte/phy/phch/phich.h b/lib/include/srslte/phy/phch/phich.h index 0645e22b1..d131dc637 100644 --- a/lib/include/srslte/phy/phch/phich.h +++ b/lib/include/srslte/phy/phch/phich.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.9 *****************************************************************************/ -#ifndef PHICH_ -#define PHICH_ +#ifndef SRSLTE_PHICH_H +#define SRSLTE_PHICH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -124,4 +124,4 @@ SRSLTE_API uint32_t srslte_phich_ngroups(srslte_phich_t *q); SRSLTE_API uint32_t srslte_phich_nsf(srslte_phich_t *q); -#endif // PHICH_ +#endif // SRSLTE_PHICH_H diff --git a/lib/include/srslte/phy/phch/pmch.h b/lib/include/srslte/phy/phch/pmch.h index dfff956f1..7d352e62a 100644 --- a/lib/include/srslte/phy/phch/pmch.h +++ b/lib/include/srslte/phy/phch/pmch.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.5 *****************************************************************************/ -#ifndef PMCH_ -#define PMCH_ +#ifndef SRSLTE_PMCH_H +#define SRSLTE_PMCH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -149,4 +149,4 @@ SRSLTE_API float srslte_pmch_average_noi(srslte_pmch_t *q); SRSLTE_API uint32_t srslte_pmch_last_noi(srslte_pmch_t *q); -#endif +#endif // SRSLTE_PMCH_H diff --git a/lib/include/srslte/phy/phch/prach.h b/lib/include/srslte/phy/phch/prach.h index 3e3df01bb..087c52957 100644 --- a/lib/include/srslte/phy/phch/prach.h +++ b/lib/include/srslte/phy/phch/prach.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 5.7 *****************************************************************************/ -#ifndef PRACH_ -#define PRACH_ +#ifndef SRSLTE_PRACH_H +#define SRSLTE_PRACH_H #include #include @@ -174,4 +174,4 @@ SRSLTE_API int srslte_prach_free(srslte_prach_t *p); SRSLTE_API int srslte_prach_print_seqs(srslte_prach_t *p); -#endif // PRACH_ +#endif // SRSLTE_PRACH_H diff --git a/lib/include/srslte/phy/phch/pucch.h b/lib/include/srslte/phy/phch/pucch.h index 29785c09a..fbb185c91 100644 --- a/lib/include/srslte/phy/phch/pucch.h +++ b/lib/include/srslte/phy/phch/pucch.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 5.4 *****************************************************************************/ -#ifndef PUCCH_ -#define PUCCH_ +#ifndef SRSLTE_PUCCH_H +#define SRSLTE_PUCCH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -211,4 +211,4 @@ SRSLTE_API bool srslte_n_pucch_isvalid(srslte_pucch_t *q, SRSLTE_API void srslte_pucch_cfg_default(srslte_pucch_cfg_t *cfg); -#endif +#endif // SRSLTE_PUCCH_H diff --git a/lib/include/srslte/phy/phch/pusch.h b/lib/include/srslte/phy/phch/pusch.h index 01db068a5..a5b8f04ae 100644 --- a/lib/include/srslte/phy/phch/pusch.h +++ b/lib/include/srslte/phy/phch/pusch.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 5.3 *****************************************************************************/ -#ifndef PUSCH_ -#define PUSCH_ +#ifndef SRSLTE_PUSCH_H +#define SRSLTE_PUSCH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -149,4 +149,4 @@ SRSLTE_API float srslte_pusch_average_noi(srslte_pusch_t *q); SRSLTE_API uint32_t srslte_pusch_last_noi(srslte_pusch_t *q); -#endif +#endif // SRSLTE_PUSCH_H diff --git a/lib/include/srslte/phy/phch/pusch_cfg.h b/lib/include/srslte/phy/phch/pusch_cfg.h index 5d743d94c..ed3239cab 100644 --- a/lib/include/srslte/phy/phch/pusch_cfg.h +++ b/lib/include/srslte/phy/phch/pusch_cfg.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.4 *****************************************************************************/ -#ifndef PUSCHCFG_ -#define PUSCHCFG_ +#ifndef SRSLTE_PUSCH_CFG_H +#define SRSLTE_PUSCH_CFG_H #include "srslte/phy/phch/ra.h" #include "srslte/phy/fec/softbuffer.h" @@ -57,5 +57,5 @@ typedef struct SRSLTE_API { uint32_t last_O_cqi; } srslte_pusch_cfg_t; -#endif +#endif // SRSLTE_PUSCH_CFG_H diff --git a/lib/include/srslte/phy/phch/ra.h b/lib/include/srslte/phy/phch/ra.h index 80097f78e..085f62b40 100644 --- a/lib/include/srslte/phy/phch/ra.h +++ b/lib/include/srslte/phy/phch/ra.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.213 version 10.0.1 Release 10 *****************************************************************************/ -#ifndef RB_ALLOC_H_ -#define RB_ALLOC_H_ +#ifndef SRSLTE_RA_H +#define SRSLTE_RA_H #include #include @@ -300,4 +300,4 @@ SRSLTE_API int srslte_dl_fill_ra_mcs_pmch(srslte_ra_mcs_t *mcs, uint32_t nprb); SRSLTE_API int srslte_dl_fill_ra_mcs(srslte_ra_mcs_t *mcs, uint32_t nprb); -#endif /* RB_ALLOC_H_ */ +#endif // SRSLTE_RA_H \ No newline at end of file diff --git a/lib/include/srslte/phy/phch/regs.h b/lib/include/srslte/phy/phch/regs.h index 8dd103f21..91e6f3338 100644 --- a/lib/include/srslte/phy/phch/regs.h +++ b/lib/include/srslte/phy/phch/regs.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 *****************************************************************************/ -#ifndef _REGS_H_ -#define _REGS_H_ +#ifndef SRSLTE_REGS_H +#define SRSLTE_REGS_H #include #include "srslte/config.h" @@ -136,6 +136,6 @@ SRSLTE_API int srslte_regs_pdcch_get_offset(srslte_regs_t *h, uint32_t start_reg, uint32_t nof_regs); -#endif // REGS_H_ +#endif // SRSLTE_REGS_H diff --git a/lib/include/srslte/phy/phch/sch.h b/lib/include/srslte/phy/phch/sch.h index e8066e4cd..4ef0328e7 100644 --- a/lib/include/srslte/phy/phch/sch.h +++ b/lib/include/srslte/phy/phch/sch.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 *****************************************************************************/ -#ifndef SCH_ -#define SCH_ +#ifndef SRSLTE_SCH_H +#define SRSLTE_SCH_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -159,4 +159,4 @@ SRSLTE_API uint32_t srslte_sch_find_Ioffset_cqi(float beta); SRSLTE_API uint32_t srslte_sch_find_Ioffset_ri(float beta); -#endif +#endif // SRSLTE_SCH_H diff --git a/lib/include/srslte/phy/phch/uci.h b/lib/include/srslte/phy/phch/uci.h index ebbd98238..4f211ff1a 100644 --- a/lib/include/srslte/phy/phch/uci.h +++ b/lib/include/srslte/phy/phch/uci.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.2.3, 5.2.4 *****************************************************************************/ -#ifndef UCI_ -#define UCI_ +#ifndef SRSLTE_UCI_H +#define SRSLTE_UCI_H #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -153,4 +153,4 @@ SRSLTE_API int srslte_uci_decode_ack_ri(srslte_pusch_cfg_t *cfg, bool is_ri); -#endif +#endif // SRSLTE_UCI_H diff --git a/lib/include/srslte/phy/resampling/decim.h b/lib/include/srslte/phy/resampling/decim.h index 22445f1b2..1394c645a 100644 --- a/lib/include/srslte/phy/resampling/decim.h +++ b/lib/include/srslte/phy/resampling/decim.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef DECIM_H -#define DECIM_H +#ifndef SRSLTE_DECIM_H +#define SRSLTE_DECIM_H #include "srslte/config.h" @@ -48,4 +48,4 @@ SRSLTE_API void srslte_decim_f(float *input, int M, int len); -#endif // DECIM_H +#endif // SRSLTE_DECIM_H diff --git a/lib/include/srslte/phy/resampling/interp.h b/lib/include/srslte/phy/resampling/interp.h index 508b6e957..8cdb8218a 100644 --- a/lib/include/srslte/phy/resampling/interp.h +++ b/lib/include/srslte/phy/resampling/interp.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef INTERP_H -#define INTERP_H +#ifndef SRSLTE_INTERP_H +#define SRSLTE_INTERP_H #include #include @@ -133,4 +133,4 @@ SRSLTE_API void srslte_interp_linear_offset(srslte_interp_lin_t *q, uint32_t off_end); -#endif // INTERP_H +#endif // SRSLTE_INTERP_H diff --git a/lib/include/srslte/phy/resampling/resample_arb.h b/lib/include/srslte/phy/resampling/resample_arb.h index 4ebb8dc08..76d873041 100644 --- a/lib/include/srslte/phy/resampling/resample_arb.h +++ b/lib/include/srslte/phy/resampling/resample_arb.h @@ -34,8 +34,8 @@ * fredric j. harris *****************************************************************************/ -#ifndef RESAMPLE_ARB_ -#define RESAMPLE_ARB_ +#ifndef SRSLTE_RESAMPLE_ARB_H +#define SRSLTE_RESAMPLE_ARB_H #include #include @@ -65,4 +65,4 @@ SRSLTE_API int srslte_resample_arb_compute(srslte_resample_arb_t *q, cf_t *output, int n_in); -#endif //RESAMPLE_ARB_ +#endif // SRSLTE_RESAMPLE_ARB_ diff --git a/lib/include/srslte/phy/rf/rf.h b/lib/include/srslte/phy/rf/rf.h index da1600b66..664d273ff 100644 --- a/lib/include/srslte/phy/rf/rf.h +++ b/lib/include/srslte/phy/rf/rf.h @@ -24,8 +24,8 @@ * */ -#ifndef RF_H -#define RF_H +#ifndef SRSLTE_RF_H +#define SRSLTE_RF_H #include #include @@ -213,5 +213,5 @@ SRSLTE_API int srslte_rf_send_multi(srslte_rf_t *rf, bool is_start_of_burst, bool is_end_of_burst); -#endif +#endif // SRSLTE_RF_H diff --git a/lib/include/srslte/phy/rf/rf_utils.h b/lib/include/srslte/phy/rf/rf_utils.h index 7dddb20f4..4cfe16461 100644 --- a/lib/include/srslte/phy/rf/rf_utils.h +++ b/lib/include/srslte/phy/rf/rf_utils.h @@ -24,6 +24,8 @@ * */ +#ifndef SRSLTE_RF_UTILS_H +#define SRSLTE_RF_UTILS_H #include "srslte/srslte.h" #include "srslte/phy/rf/rf.h" @@ -62,4 +64,5 @@ SRSLTE_API int rf_search_and_decode_mib(srslte_rf_t *rf, srslte_cell_t *cell, float *cfo); +#endif // SRSLTE_RF_UTILS_H diff --git a/lib/include/srslte/phy/scrambling/scrambling.h b/lib/include/srslte/phy/scrambling/scrambling.h index 4fa74790a..c38bbe8c9 100644 --- a/lib/include/srslte/phy/scrambling/scrambling.h +++ b/lib/include/srslte/phy/scrambling/scrambling.h @@ -32,8 +32,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 5.3.1, 6.3.1 *****************************************************************************/ -#ifndef SCRAMBLING_ -#define SCRAMBLING_ +#ifndef SRSLTE_SCRAMBLING_H +#define SRSLTE_SCRAMBLING_H #include "srslte/config.h" #include "srslte/phy/common/sequence.h" @@ -76,4 +76,4 @@ SRSLTE_API void srslte_scrambling_c_offset(srslte_sequence_t *s, int offset, int len); -#endif // SCRAMBLING_ +#endif // SRSLTE_SCRAMBLING_H diff --git a/lib/include/srslte/phy/sync/cfo.h b/lib/include/srslte/phy/sync/cfo.h index 506732b74..b28d57d33 100644 --- a/lib/include/srslte/phy/sync/cfo.h +++ b/lib/include/srslte/phy/sync/cfo.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef CFO_ -#define CFO_ +#ifndef SRSLTE_CFO_H +#define SRSLTE_CFO_H #include @@ -67,4 +67,4 @@ SRSLTE_API void srslte_cfo_correct(srslte_cfo_t *h, cf_t *output, float freq); -#endif // CFO_ +#endif // SRSLTE_CFO_H diff --git a/lib/include/srslte/phy/sync/cp.h b/lib/include/srslte/phy/sync/cp.h index d9da03722..511efb426 100644 --- a/lib/include/srslte/phy/sync/cp.h +++ b/lib/include/srslte/phy/sync/cp.h @@ -24,8 +24,8 @@ * */ -#ifndef CP_ -#define CP_ +#ifndef SRSLTE_CP_H +#define SRSLTE_CP_H #include #include @@ -55,4 +55,4 @@ SRSLTE_API uint32_t srslte_cp_synch(srslte_cp_synch_t *q, SRSLTE_API cf_t srslte_cp_synch_corr_output(srslte_cp_synch_t *q, uint32_t offset); -#endif // CP_ +#endif // SRSLTE_CP_H diff --git a/lib/include/srslte/phy/sync/pss.h b/lib/include/srslte/phy/sync/pss.h index 922bc0286..520e2bcec 100644 --- a/lib/include/srslte/phy/sync/pss.h +++ b/lib/include/srslte/phy/sync/pss.h @@ -42,8 +42,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.11.1 *****************************************************************************/ -#ifndef PSS_ -#define PSS_ +#ifndef SRSLTE_PSS_H +#define SRSLTE_PSS_H #include #include @@ -176,4 +176,4 @@ SRSLTE_API int srslte_pss_chest(srslte_pss_t *q, SRSLTE_API float srslte_pss_cfo_compute(srslte_pss_t* q, const cf_t *pss_recv); -#endif // PSS_ +#endif // SRSLTE_PSS_H diff --git a/lib/include/srslte/phy/sync/sfo.h b/lib/include/srslte/phy/sync/sfo.h index f6f94c9a3..a42ced471 100644 --- a/lib/include/srslte/phy/sync/sfo.h +++ b/lib/include/srslte/phy/sync/sfo.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef SFO_ -#define SFO_ +#ifndef SRSLTE_SFO_H +#define SRSLTE_SFO_H #include "srslte/config.h" @@ -46,4 +46,4 @@ SRSLTE_API float srslte_sfo_estimate_period(int *t0, int len, float period); -#endif // SFO_ +#endif // SRSLTE_SFO_H diff --git a/lib/include/srslte/phy/sync/sss.h b/lib/include/srslte/phy/sync/sss.h index 9f77d1ce6..a0062d63b 100644 --- a/lib/include/srslte/phy/sync/sss.h +++ b/lib/include/srslte/phy/sync/sss.h @@ -33,8 +33,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.11.2 *****************************************************************************/ -#ifndef SSS_ -#define SSS_ +#ifndef SRSLTE_SSS_H +#define SRSLTE_SSS_H #include #include @@ -153,5 +153,5 @@ SRSLTE_API void srslte_sss_set_symbol_sz(srslte_sss_t *q, SRSLTE_API void srslte_sss_set_subframe_sz(srslte_sss_t *q, uint32_t subframe_sz); -#endif // SSS_ +#endif // SRSLTE_SSS_H diff --git a/lib/include/srslte/phy/sync/sync.h b/lib/include/srslte/phy/sync/sync.h index 232bc5fc4..f99bfc17a 100644 --- a/lib/include/srslte/phy/sync/sync.h +++ b/lib/include/srslte/phy/sync/sync.h @@ -42,8 +42,8 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.11.1, 6.11.2 *****************************************************************************/ -#ifndef SYNC_ -#define SYNC_ +#ifndef SRSLTE_SYNC_H +#define SRSLTE_SYNC_H #include #include @@ -240,5 +240,5 @@ SRSLTE_API bool srslte_sync_sss_detected(srslte_sync_t *q); SRSLTE_API void srslte_sync_cp_en(srslte_sync_t *q, bool enabled); -#endif // SYNC_ +#endif // SRSLTE_SYNC_H diff --git a/lib/include/srslte/phy/ue/ue_cell_search.h b/lib/include/srslte/phy/ue/ue_cell_search.h index bcabe1728..e99e916d4 100644 --- a/lib/include/srslte/phy/ue/ue_cell_search.h +++ b/lib/include/srslte/phy/ue/ue_cell_search.h @@ -40,8 +40,8 @@ * Reference: *****************************************************************************/ -#ifndef UE_CELLSEARCH_ -#define UE_CELLSEARCH_ +#ifndef SRSLTE_UE_CELL_SEARCH_H +#define SRSLTE_UE_CELL_SEARCH_H #include @@ -110,5 +110,5 @@ SRSLTE_API int srslte_ue_cellsearch_set_nof_valid_frames(srslte_ue_cellsearch_t -#endif // SYNC_FRAME_ +#endif // SRSLTE_UE_CELL_SEARCH_H diff --git a/lib/include/srslte/phy/ue/ue_dl.h b/lib/include/srslte/phy/ue/ue_dl.h index c5b0da52a..197a650b1 100644 --- a/lib/include/srslte/phy/ue/ue_dl.h +++ b/lib/include/srslte/phy/ue/ue_dl.h @@ -35,8 +35,8 @@ * Reference: *****************************************************************************/ -#ifndef UEDL_H -#define UEDL_H +#ifndef SRSLTE_UE_DL_H +#define SRSLTE_UE_DL_H #include @@ -254,4 +254,4 @@ SRSLTE_API void srslte_ue_dl_save_signal(srslte_ue_dl_t *q, uint32_t cfi); -#endif +#endif // SRSLTE_UE_DL_H diff --git a/lib/include/srslte/phy/ue/ue_mib.h b/lib/include/srslte/phy/ue/ue_mib.h index ee52b31d4..38f27d024 100644 --- a/lib/include/srslte/phy/ue/ue_mib.h +++ b/lib/include/srslte/phy/ue/ue_mib.h @@ -43,8 +43,8 @@ * Reference: *****************************************************************************/ -#ifndef UE_MIB_ -#define UE_MIB_ +#ifndef SRSLTE_UE_MIB_H +#define SRSLTE_UE_MIB_H #include @@ -129,5 +129,5 @@ SRSLTE_API int srslte_ue_mib_sync_decode(srslte_ue_mib_sync_t * q, -#endif // SYNC_FRAME_ +#endif // SRSLTE_UE_MIB_H diff --git a/lib/include/srslte/phy/ue/ue_phy.h b/lib/include/srslte/phy/ue/ue_phy.h index 369b96027..0a8217594 100644 --- a/lib/include/srslte/phy/ue/ue_phy.h +++ b/lib/include/srslte/phy/ue/ue_phy.h @@ -35,8 +35,8 @@ #include "srslte/srslte.h" #include "srslte/phy/utils/queue.h" -#ifndef UEPHY_H -#define UEPHY_H +#ifndef SRSLTE_UE_PHY_H +#define SRSLTE_UE_PHY_H #define SYNC_MODE_CV 0 #define SYNC_MODE_CALLBACK 1 @@ -165,4 +165,4 @@ private: }; } -#endif +#endif // SRSLTE_UE_PHY_H diff --git a/lib/include/srslte/phy/ue/ue_sync.h b/lib/include/srslte/phy/ue/ue_sync.h index a5e126e5f..3d9807aea 100644 --- a/lib/include/srslte/phy/ue/ue_sync.h +++ b/lib/include/srslte/phy/ue/ue_sync.h @@ -46,8 +46,8 @@ * Reference: *****************************************************************************/ -#ifndef UE_SYNC_ -#define UE_SYNC_ +#ifndef SRSLTE_UE_SYNC_H +#define SRSLTE_UE_SYNC_H #include @@ -255,5 +255,5 @@ SRSLTE_API void srslte_ue_sync_get_last_timestamp(srslte_ue_sync_t *q, srslte_timestamp_t *timestamp); -#endif // SYNC_FRAME_ +#endif // SRSLTE_UE_SYNC_H diff --git a/lib/include/srslte/phy/ue/ue_ul.h b/lib/include/srslte/phy/ue/ue_ul.h index 617833a61..98dae48b4 100644 --- a/lib/include/srslte/phy/ue/ue_ul.h +++ b/lib/include/srslte/phy/ue/ue_ul.h @@ -35,8 +35,8 @@ * Reference: *****************************************************************************/ -#ifndef UEUL_H -#define UEUL_H +#ifndef SRSLTE_UE_UL_H +#define SRSLTE_UE_UL_H #include "srslte/phy/common/phy_common.h" #include "srslte/phy/ch_estimation/chest_dl.h" @@ -210,4 +210,4 @@ SRSLTE_API bool srslte_ue_ul_srs_tx_enabled(srslte_refsignal_srs_cfg_t *srs_cfg, uint32_t tti); -#endif +#endif // SRSLTE_UE_UL_H diff --git a/lib/include/srslte/phy/utils/bit.h b/lib/include/srslte/phy/utils/bit.h index e4289b790..29fca8e9e 100644 --- a/lib/include/srslte/phy/utils/bit.h +++ b/lib/include/srslte/phy/utils/bit.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef BIT_ -#define BIT_ +#ifndef SRSLTE_BIT_H +#define SRSLTE_BIT_H #include #include @@ -108,5 +108,5 @@ SRSLTE_API uint32_t srslte_bit_diff(uint8_t *x, SRSLTE_API uint32_t srslte_bit_count(uint32_t n); -#endif // BIT_ +#endif // SRSLTE_BIT_H diff --git a/lib/include/srslte/phy/utils/cexptab.h b/lib/include/srslte/phy/utils/cexptab.h index f615ede22..b96b330a9 100644 --- a/lib/include/srslte/phy/utils/cexptab.h +++ b/lib/include/srslte/phy/utils/cexptab.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef CEXPTAB_ -#define CEXPTAB_ +#ifndef SRSLTE_CEXPTAB_H +#define SRSLTE_CEXPTAB_H #include #include @@ -58,4 +58,4 @@ SRSLTE_API void srslte_cexptab_gen_direct(cf_t *x, float freq, uint32_t len); -#endif // CEXPTAB_ +#endif // SRSLTE_CEXPTAB_H diff --git a/lib/include/srslte/phy/utils/convolution.h b/lib/include/srslte/phy/utils/convolution.h index a93dfb955..3f0cad7aa 100644 --- a/lib/include/srslte/phy/utils/convolution.h +++ b/lib/include/srslte/phy/utils/convolution.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef CONVOLUTION_H_ -#define CONVOLUTION_H_ +#ifndef SRSLTE_CONVOLUTION_H +#define SRSLTE_CONVOLUTION_H #include "srslte/config.h" #include "srslte/phy/dft/dft.h" @@ -94,4 +94,4 @@ SRSLTE_API uint32_t srslte_conv_same_cc(cf_t *input, uint32_t input_len, uint32_t filter_len); -#endif // CONVOLUTION_H_ +#endif // SRSLTE_CONVOLUTION_H diff --git a/lib/include/srslte/phy/utils/debug.h b/lib/include/srslte/phy/utils/debug.h index 52290ca11..9a07272b6 100644 --- a/lib/include/srslte/phy/utils/debug.h +++ b/lib/include/srslte/phy/utils/debug.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef DEBUG_H -#define DEBUG_H +#ifndef SRSLTE_DEBUG_H +#define SRSLTE_DEBUG_H #include #include "srslte/config.h" @@ -80,4 +80,4 @@ SRSLTE_API extern int handler_registered; void srslte_debug_handle_crash(int argc, char **argv); -#endif // DEBUG_H +#endif // SRSLTE_DEBUG_H diff --git a/lib/include/srslte/phy/utils/filter.h b/lib/include/srslte/phy/utils/filter.h index 70e00363c..a126e171b 100644 --- a/lib/include/srslte/phy/utils/filter.h +++ b/lib/include/srslte/phy/utils/filter.h @@ -32,8 +32,9 @@ * Reference: *****************************************************************************/ -#ifndef FILTER_H -#define FILTER_H +#ifndef SRSLTE_FILTER_H +#define SRSLTE_FILTER_H + #include #include #include "srslte/config.h" @@ -57,4 +58,4 @@ void srslte_filt_decim_cc_free(srslte_filt_cc_t *q); void srslte_filt_decim_cc_execute(srslte_filt_cc_t *q, cf_t *input, cf_t *downsampled_input, cf_t *output, int size); void srslte_downsample_cc(cf_t *input, cf_t *output, int M, int size) ; -#endif // FILTER_H \ No newline at end of file +#endif // SRSLTE_FILTER_H \ No newline at end of file diff --git a/lib/include/srslte/phy/utils/mat.h b/lib/include/srslte/phy/utils/mat.h index 339cfea23..a0f11abe3 100644 --- a/lib/include/srslte/phy/utils/mat.h +++ b/lib/include/srslte/phy/utils/mat.h @@ -103,4 +103,4 @@ SRSLTE_API void srslte_mat_2x2_mmse_avx(__m256 y0, __m256 y1, #endif /* LV_HAVE_AVX */ -#endif /* SRSLTE_MAT_H */ +#endif // SRSLTE_MAT_H diff --git a/lib/include/srslte/phy/utils/ringbuffer.h b/lib/include/srslte/phy/utils/ringbuffer.h index a93ebf181..b7a852155 100644 --- a/lib/include/srslte/phy/utils/ringbuffer.h +++ b/lib/include/srslte/phy/utils/ringbuffer.h @@ -1,6 +1,6 @@ -#ifndef RINGBUFFER_H -#define RINGBUFFER_H +#ifndef SRSLTE_RINGBUFFER_H +#define SRSLTE_RINGBUFFER_H #include "srslte/config.h" #include @@ -40,6 +40,6 @@ SRSLTE_API int srslte_ringbuffer_read(srslte_ringbuffer_t *q, SRSLTE_API void srslte_ringbuffer_stop(srslte_ringbuffer_t *q); -#endif +#endif // SRSLTE_RINGBUFFER_H diff --git a/lib/include/srslte/phy/utils/simd.h b/lib/include/srslte/phy/utils/simd.h index 3223c18a7..66295f2ce 100644 --- a/lib/include/srslte/phy/utils/simd.h +++ b/lib/include/srslte/phy/utils/simd.h @@ -24,8 +24,8 @@ * */ -#ifndef SRSLTE_SIMD_H_H -#define SRSLTE_SIMD_H_H +#ifndef SRSLTE_SIMD_H +#define SRSLTE_SIMD_H #ifdef LV_HAVE_SSE /* AVX, AVX2, FMA, AVX512 are in this group */ #ifndef __OPTIMIZE__ @@ -1636,4 +1636,4 @@ static inline simd_b_t srslte_simd_b_xor(simd_b_t a, simd_b_t b) { #endif /*SRSLTE_SIMD_B_SIZE */ -#endif //SRSLTE_SIMD_H_H +#endif // SRSLTE_SIMD_H diff --git a/lib/include/srslte/phy/utils/vector.h b/lib/include/srslte/phy/utils/vector.h index fbf000a70..1fcbe4235 100644 --- a/lib/include/srslte/phy/utils/vector.h +++ b/lib/include/srslte/phy/utils/vector.h @@ -32,8 +32,8 @@ * Reference: *****************************************************************************/ -#ifndef VECTOR_ -#define VECTOR_ +#ifndef SRSLTE_VECTOR_H +#define SRSLTE_VECTOR_H #ifdef __cplusplus extern "C" { @@ -159,4 +159,4 @@ SRSLTE_API void srslte_vec_interleave_add(const cf_t *x, const cf_t *y, cf_t *z, } #endif -#endif // VECTOR_ +#endif // SRSLTE_VECTOR_H diff --git a/lib/include/srslte/phy/utils/vector_simd.h b/lib/include/srslte/phy/utils/vector_simd.h index 8139d0e78..11c6ce1cd 100644 --- a/lib/include/srslte/phy/utils/vector_simd.h +++ b/lib/include/srslte/phy/utils/vector_simd.h @@ -24,8 +24,8 @@ * */ -#ifndef VECTORSIMD_ -#define VECTORSIMD_ +#ifndef SRSLTE_VECTOR_SIMD_H +#define SRSLTE_VECTOR_SIMD_H #ifdef __cplusplus extern "C" { @@ -139,4 +139,4 @@ SRSLTE_API uint32_t srslte_vec_max_ci_simd(const cf_t *x, const int len); } #endif -#endif +#endif // SRSLTE_VECTOR_SIMD_H diff --git a/lib/include/srslte/radio/radio.h b/lib/include/srslte/radio/radio.h index 143927730..26775777b 100644 --- a/lib/include/srslte/radio/radio.h +++ b/lib/include/srslte/radio/radio.h @@ -30,8 +30,8 @@ #include "srslte/phy/rf/rf.h" #include "srslte/common/trace.h" -#ifndef RADIO_H -#define RADIO_H +#ifndef SRSLTE_RADIO_H +#define SRSLTE_RADIO_H typedef struct { float tx_corr_dc_gain; @@ -180,4 +180,4 @@ namespace srslte { }; } -#endif +#endif // SRSLTE_RADIO_H diff --git a/lib/include/srslte/radio/radio_multi.h b/lib/include/srslte/radio/radio_multi.h index d83237619..efb1e31b6 100644 --- a/lib/include/srslte/radio/radio_multi.h +++ b/lib/include/srslte/radio/radio_multi.h @@ -34,8 +34,8 @@ extern "C" { #include "srslte/radio/radio.h" -#ifndef RADIO_MULTI_H -#define RADIO_MULTI_H +#ifndef SRSLTE_RADIO_MULTI_H +#define SRSLTE_RADIO_MULTI_H namespace srslte { @@ -51,4 +51,4 @@ namespace srslte { }; } -#endif +#endif // SRSLTE_RADIO_MULTI_H diff --git a/lib/include/srslte/srslte.h b/lib/include/srslte/srslte.h index 36af629d7..f87a1bf2c 100644 --- a/lib/include/srslte/srslte.h +++ b/lib/include/srslte/srslte.h @@ -25,8 +25,8 @@ */ -#ifndef _LTE_ -#define _LTE_ +#ifndef SRSLTE_SRSLTE_H +#define SRSLTE_SRSLTE_H #ifdef __cplusplus extern "C" { @@ -128,4 +128,4 @@ #undef I // Fix complex.h #define I nastiness when using C++ #endif -#endif +#endif // SRSLTE_SRSLTE_H diff --git a/lib/include/srslte/upper/pdcp.h b/lib/include/srslte/upper/pdcp.h index 584b231a3..436f35edd 100644 --- a/lib/include/srslte/upper/pdcp.h +++ b/lib/include/srslte/upper/pdcp.h @@ -24,8 +24,8 @@ * */ -#ifndef PDCP_H -#define PDCP_H +#ifndef SRSLTE_PDCP_H +#define SRSLTE_PDCP_H #include "srslte/common/log.h" #include "srslte/common/common.h" @@ -89,7 +89,7 @@ private: bool valid_lcid(uint32_t lcid); }; -} // namespace srsue +} // namespace srslte -#endif // PDCP_H +#endif // SRSLTE_PDCP_H diff --git a/lib/include/srslte/upper/pdcp_entity.h b/lib/include/srslte/upper/pdcp_entity.h index 0894b6578..e8a5d9561 100644 --- a/lib/include/srslte/upper/pdcp_entity.h +++ b/lib/include/srslte/upper/pdcp_entity.h @@ -24,8 +24,8 @@ * */ -#ifndef PDCP_ENTITY_H -#define PDCP_ENTITY_H +#ifndef SRSLTE_PDCP_ENTITY_H +#define SRSLTE_PDCP_ENTITY_H #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" @@ -144,7 +144,7 @@ void pdcp_unpack_data_pdu_short_sn(byte_buffer_t *sdu, uint32_t *sn); void pdcp_pack_data_pdu_long_sn(uint32_t sn, byte_buffer_t *sdu); void pdcp_unpack_data_pdu_long_sn(byte_buffer_t *sdu, uint32_t *sn); -} // namespace srsue +} // namespace srslte -#endif // PDCP_ENTITY_H +#endif // SRSLTE_PDCP_ENTITY_H diff --git a/lib/include/srslte/upper/rlc.h b/lib/include/srslte/upper/rlc.h index e9036a011..c4d57b9bb 100644 --- a/lib/include/srslte/upper/rlc.h +++ b/lib/include/srslte/upper/rlc.h @@ -24,8 +24,8 @@ * */ -#ifndef RLC_H -#define RLC_H +#ifndef SRSLTE_RLC_H +#define SRSLTE_RLC_H #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" @@ -105,4 +105,4 @@ private: } // namespace srsue -#endif // RLC_H +#endif // SRSLTE_RLC_H diff --git a/lib/include/srslte/upper/rlc_am.h b/lib/include/srslte/upper/rlc_am.h index 7601baefa..894f96ac5 100644 --- a/lib/include/srslte/upper/rlc_am.h +++ b/lib/include/srslte/upper/rlc_am.h @@ -24,8 +24,8 @@ * */ -#ifndef RLC_AM_H -#define RLC_AM_H +#ifndef SRSLTE_RLC_AM_H +#define SRSLTE_RLC_AM_H #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" @@ -220,7 +220,7 @@ std::string rlc_am_to_string(rlc_status_pdu_t *status); bool rlc_am_start_aligned(uint8_t fi); bool rlc_am_end_aligned(uint8_t fi); -} // namespace srsue +} // namespace srslte -#endif // RLC_AM_H +#endif // SRSLTE_RLC_AM_H diff --git a/lib/include/srslte/upper/rlc_common.h b/lib/include/srslte/upper/rlc_common.h index 494cc6174..9be390d31 100644 --- a/lib/include/srslte/upper/rlc_common.h +++ b/lib/include/srslte/upper/rlc_common.h @@ -24,8 +24,8 @@ * */ -#ifndef RLC_COMMON_H -#define RLC_COMMON_H +#ifndef SRSLTE_RLC_COMMON_H +#define SRSLTE_RLC_COMMON_H #include "srslte/upper/rlc_interface.h" @@ -176,4 +176,4 @@ public: } // namespace srslte -#endif // RLC_COMMON_H +#endif // SRSLTE_RLC_COMMON_H diff --git a/lib/include/srslte/upper/rlc_entity.h b/lib/include/srslte/upper/rlc_entity.h index de4a396fe..cd30d5999 100644 --- a/lib/include/srslte/upper/rlc_entity.h +++ b/lib/include/srslte/upper/rlc_entity.h @@ -24,8 +24,8 @@ * */ -#ifndef RLC_ENTITY_H -#define RLC_ENTITY_H +#ifndef SRSLTE_RLC_ENTITY_H +#define SRSLTE_RLC_ENTITY_H #include "srslte/common/log.h" #include "srslte/common/common.h" @@ -82,7 +82,7 @@ private: rlc_common *rlc; }; -} // namespace srsue +} // namespace srslte -#endif // RLC_ENTITY_H +#endif // SRSLTE_RLC_ENTITY_H diff --git a/lib/include/srslte/upper/rlc_interface.h b/lib/include/srslte/upper/rlc_interface.h index feddac1cc..8c869ceb9 100644 --- a/lib/include/srslte/upper/rlc_interface.h +++ b/lib/include/srslte/upper/rlc_interface.h @@ -24,8 +24,8 @@ * */ -#ifndef RLC_INTERFACE_H -#define RLC_INTERFACE_H +#ifndef SRSLTE_RLC_INTERFACE_H +#define SRSLTE_RLC_INTERFACE_H // for custom constructors #include "srslte/asn1/liblte_rrc.h" @@ -123,4 +123,4 @@ public: } // namespace srslte -#endif // RLC_INTERFACE_H +#endif // SRSLTE_RLC_INTERFACE_H diff --git a/lib/include/srslte/upper/rlc_metrics.h b/lib/include/srslte/upper/rlc_metrics.h index 0089ab5a6..ab6e83c02 100644 --- a/lib/include/srslte/upper/rlc_metrics.h +++ b/lib/include/srslte/upper/rlc_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef UE_RLC_METRICS_H -#define UE_RLC_METRICS_H +#ifndef SRSLTE_RLC_METRICS_H +#define SRSLTE_RLC_METRICS_H namespace srslte { @@ -36,6 +36,6 @@ struct rlc_metrics_t float ul_tput_mbps; }; -} // namespace srsue +} // namespace srslte -#endif // UE_RLC_METRICS_H +#endif // SRSLTE_RLC_METRICS_H diff --git a/lib/include/srslte/upper/rlc_tm.h b/lib/include/srslte/upper/rlc_tm.h index 4a55e33dd..5408cb835 100644 --- a/lib/include/srslte/upper/rlc_tm.h +++ b/lib/include/srslte/upper/rlc_tm.h @@ -24,8 +24,8 @@ * */ -#ifndef RLC_TM_H -#define RLC_TM_H +#ifndef SRSLTE_RLC_TM_H +#define SRSLTE_RLC_TM_H #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" @@ -78,4 +78,4 @@ private: } // namespace srsue -#endif // RLC_TM_H +#endif // SRSLTE_RLC_TM_H diff --git a/lib/include/srslte/upper/rlc_um.h b/lib/include/srslte/upper/rlc_um.h index 6d8eb6d08..8e6f527e2 100644 --- a/lib/include/srslte/upper/rlc_um.h +++ b/lib/include/srslte/upper/rlc_um.h @@ -24,8 +24,8 @@ * */ -#ifndef RLC_UM_H -#define RLC_UM_H +#ifndef SRSLTE_RLC_UM_H +#define SRSLTE_RLC_UM_H #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" @@ -153,4 +153,4 @@ bool rlc_um_end_aligned(uint8_t fi); } // namespace srsue -#endif // RLC_UM_H +#endif // SRSLTE_RLC_UM_H diff --git a/lib/include/srslte/version.h.in b/lib/include/srslte/version.h.in index 65a172725..f50a6f9bf 100644 --- a/lib/include/srslte/version.h.in +++ b/lib/include/srslte/version.h.in @@ -25,8 +25,8 @@ * */ -#ifndef VERSION_ -#define VERSION_ +#ifndef SRSLTE_VERSION_H_IN +#define SRSLTE_VERSION_H_IN // the configured options and settings for SRSLTE #define SRSLTE_VERSION_MAJOR @SRSLTE_VERSION_MAJOR@ diff --git a/srsenb/hdr/cfg_parser.h b/srsenb/hdr/cfg_parser.h index 56b5e6e63..d399ddae3 100644 --- a/srsenb/hdr/cfg_parser.h +++ b/srsenb/hdr/cfg_parser.h @@ -24,8 +24,8 @@ * */ -#ifndef CFG_PARSER_H -#define CFG_PARSER_H +#ifndef SRSENB_CFG_PARSER_H +#define SRSENB_CFG_PARSER_H #include "enb.h" diff --git a/srsenb/hdr/enb.h b/srsenb/hdr/enb.h index 6d2a78b44..745096daa 100644 --- a/srsenb/hdr/enb.h +++ b/srsenb/hdr/enb.h @@ -30,8 +30,8 @@ * layers and helpers. *****************************************************************************/ -#ifndef ENB_H -#define ENB_H +#ifndef SRSENB_ENB_H +#define SRSENB_ENB_H #include #include @@ -219,5 +219,5 @@ private: } // namespace srsenb -#endif // UE_H +#endif // SRSENB_ENB_H diff --git a/srsenb/hdr/mac/mac.h b/srsenb/hdr/mac/mac.h index c99b733fb..af122e36b 100644 --- a/srsenb/hdr/mac/mac.h +++ b/srsenb/hdr/mac/mac.h @@ -24,8 +24,8 @@ * */ -#ifndef MAC_H -#define MAC_H +#ifndef SRSENB_MAC_H +#define SRSENB_MAC_H #include #include "srslte/common/log.h" @@ -211,6 +211,6 @@ private: }; -} // namespace srsue +} // namespace srsenb -#endif // MAC_H +#endif // SRSENB_MAC_H diff --git a/srsenb/hdr/mac/mac_metrics.h b/srsenb/hdr/mac/mac_metrics.h index e11eda350..d63734d2a 100644 --- a/srsenb/hdr/mac/mac_metrics.h +++ b/srsenb/hdr/mac/mac_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef ENB_MAC_METRICS_H -#define ENB_MAC_METRICS_H +#ifndef SRSENB_MAC_METRICS_H +#define SRSENB_MAC_METRICS_H namespace srsenb { @@ -51,4 +51,4 @@ struct mac_metrics_t } // namespace srsenb -#endif // ENB_MAC_METRICS_H +#endif // SRSENB_MAC_METRICS_H diff --git a/srsenb/hdr/mac/scheduler.h b/srsenb/hdr/mac/scheduler.h index 12c336c36..d964726d9 100644 --- a/srsenb/hdr/mac/scheduler.h +++ b/srsenb/hdr/mac/scheduler.h @@ -24,8 +24,8 @@ * */ -#ifndef SCHED_H -#define SCHED_H +#ifndef SRSENB_SCHEDULER_H +#define SRSENB_SCHEDULER_H #include #include "srslte/common/log.h" @@ -228,4 +228,4 @@ private: } -#endif +#endif // SRSENB_SCHEDULER_H diff --git a/srsenb/hdr/mac/scheduler_harq.h b/srsenb/hdr/mac/scheduler_harq.h index ec2aa43c0..7002653e3 100644 --- a/srsenb/hdr/mac/scheduler_harq.h +++ b/srsenb/hdr/mac/scheduler_harq.h @@ -24,8 +24,8 @@ * */ -#ifndef SCHED_HARQ_H -#define SCHED_HARQ_H +#ifndef SRSENB_SCHEDULER_HARQ_H +#define SRSENB_SCHEDULER_HARQ_H #include #include "srslte/common/log.h" @@ -125,4 +125,4 @@ private: } -#endif +#endif // SRSENB_SCHEDULER_HARQ_H diff --git a/srsenb/hdr/mac/scheduler_metric.h b/srsenb/hdr/mac/scheduler_metric.h index eda0b31ed..385d5803d 100644 --- a/srsenb/hdr/mac/scheduler_metric.h +++ b/srsenb/hdr/mac/scheduler_metric.h @@ -24,8 +24,8 @@ * */ -#ifndef SCHED_METRIC_H -#define SCHED_METRIC_H +#ifndef SRSENB_SCHEDULER_METRIC_H +#define SRSENB_SCHEDULER_METRIC_H #include "mac/scheduler.h" @@ -84,5 +84,5 @@ private: } -#endif +#endif // SRSENB_SCHEDULER_METRIC_H diff --git a/srsenb/hdr/mac/scheduler_ue.h b/srsenb/hdr/mac/scheduler_ue.h index 448e01954..90db552a6 100644 --- a/srsenb/hdr/mac/scheduler_ue.h +++ b/srsenb/hdr/mac/scheduler_ue.h @@ -24,8 +24,8 @@ * */ -#ifndef SCHED_UE_H -#define SCHED_UE_H +#ifndef SRSENB_SCHEDULER_UE_H +#define SRSENB_SCHEDULER_UE_H #include #include "srslte/common/log.h" @@ -194,4 +194,4 @@ private: } -#endif +#endif // SRSENB_SCHEDULER_UE_H diff --git a/srsenb/hdr/mac/ue.h b/srsenb/hdr/mac/ue.h index 3b81a10ec..405acd120 100644 --- a/srsenb/hdr/mac/ue.h +++ b/srsenb/hdr/mac/ue.h @@ -24,8 +24,8 @@ * */ -#ifndef UE_H -#define UE_H +#ifndef SRSENB_UE_H +#define SRSENB_UE_H #include "srslte/common/log.h" #include "srslte/common/pdu.h" @@ -167,5 +167,5 @@ private: } -#endif +#endif // SRSENB_UE_H diff --git a/srsenb/hdr/metrics_stdout.h b/srsenb/hdr/metrics_stdout.h index 563a866d3..f5af14e25 100644 --- a/srsenb/hdr/metrics_stdout.h +++ b/srsenb/hdr/metrics_stdout.h @@ -30,8 +30,8 @@ * Description: Metrics class printing to stdout. *****************************************************************************/ -#ifndef METRICS_STDOUT_H -#define METRICS_STDOUT_H +#ifndef SRSENB_METRICS_STDOUT_H +#define SRSENB_METRICS_STDOUT_H #include #include @@ -71,4 +71,4 @@ private: } // namespace srsenb -#endif // METRICS_STDOUT_H +#endif // SRSENB_METRICS_STDOUT_H diff --git a/srsenb/hdr/parser.h b/srsenb/hdr/parser.h index 492249e18..90425203f 100644 --- a/srsenb/hdr/parser.h +++ b/srsenb/hdr/parser.h @@ -24,8 +24,8 @@ * */ -#ifndef PARSER_H -#define PARSER_H +#ifndef SRSENB_PARSER_H +#define SRSENB_PARSER_H #include #include diff --git a/srsenb/hdr/phy/phch_common.h b/srsenb/hdr/phy/phch_common.h index 5ce9237bf..6adc926f3 100644 --- a/srsenb/hdr/phy/phch_common.h +++ b/srsenb/hdr/phy/phch_common.h @@ -24,8 +24,8 @@ * */ -#ifndef ENBPHCHCOMMON_H -#define ENBPHCHCOMMON_H +#ifndef SRSENB_PHCH_COMMON_H +#define SRSENB_PHCH_COMMON_H #include #include "srslte/interfaces/enb_interfaces.h" @@ -133,4 +133,4 @@ private: } // namespace srsenb -#endif // UEPHY_H +#endif // SRSENB_PHCH_COMMON_H diff --git a/srsenb/hdr/phy/phch_worker.h b/srsenb/hdr/phy/phch_worker.h index 789e2593a..35e0607ba 100644 --- a/srsenb/hdr/phy/phch_worker.h +++ b/srsenb/hdr/phy/phch_worker.h @@ -24,8 +24,8 @@ * */ -#ifndef ENBPHYWORKER_H -#define ENBPHYWORKER_H +#ifndef SRSENB_PHCH_WORKER_H +#define SRSENB_PHCH_WORKER_H #include @@ -137,5 +137,5 @@ private: } // namespace srsenb -#endif // ENBPHYWORKER_H +#endif // SRSENB_PHCH_WORKER_H diff --git a/srsenb/hdr/phy/phy.h b/srsenb/hdr/phy/phy.h index 99b23de0c..07c181741 100644 --- a/srsenb/hdr/phy/phy.h +++ b/srsenb/hdr/phy/phy.h @@ -24,8 +24,8 @@ * */ -#ifndef ENBPHY_H -#define ENBPHY_H +#ifndef SRSENB_PHY_H +#define SRSENB_PHY_H #include "srslte/common/log.h" #include "srslte/common/log_filter.h" @@ -99,4 +99,4 @@ private: } // namespace srsenb -#endif // UEPHY_H +#endif // SRSENB_PHY_H diff --git a/srsenb/hdr/phy/phy_metrics.h b/srsenb/hdr/phy/phy_metrics.h index ad3b96698..5a45baf5f 100644 --- a/srsenb/hdr/phy/phy_metrics.h +++ b/srsenb/hdr/phy/phy_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef ENB_PHY_METRICS_H -#define ENB_PHY_METRICS_H +#ifndef SRSENB_PHY_METRICS_H +#define SRSENB_PHY_METRICS_H namespace srsenb { @@ -56,4 +56,4 @@ struct phy_metrics_t } // namespace srsenb -#endif // ENB_PHY_METRICS_H +#endif // SRSENB_PHY_METRICS_H diff --git a/srsenb/hdr/phy/prach_worker.h b/srsenb/hdr/phy/prach_worker.h index dd1149dd4..8ca70aa60 100644 --- a/srsenb/hdr/phy/prach_worker.h +++ b/srsenb/hdr/phy/prach_worker.h @@ -24,8 +24,8 @@ * */ -#ifndef PRACH_WORKER_H -#define PRACH_WORKER_H +#ifndef SRSENB_PRACH_WORKER_H +#define SRSENB_PRACH_WORKER_H #include "srslte/interfaces/enb_interfaces.h" #include "srslte/common/log.h" @@ -85,4 +85,4 @@ private: uint32_t sf_cnt; }; } -#endif // PRACH_WORKER_H +#endif // SRSENB_PRACH_WORKER_H diff --git a/srsenb/hdr/phy/txrx.h b/srsenb/hdr/phy/txrx.h index 035f81f9c..9ba048c83 100644 --- a/srsenb/hdr/phy/txrx.h +++ b/srsenb/hdr/phy/txrx.h @@ -24,8 +24,8 @@ * */ -#ifndef ENBTXRX_H -#define ENBTXRX_H +#ifndef SRSENB_TXRX_H +#define SRSENB_TXRX_H #include "srslte/common/log.h" #include "srslte/common/threads.h" @@ -73,4 +73,4 @@ private: } // namespace srsenb -#endif // UEPHY_H +#endif // SRSENB_TXRX_H diff --git a/srsenb/hdr/upper/common_enb.h b/srsenb/hdr/upper/common_enb.h index d04869c54..2e0b28917 100644 --- a/srsenb/hdr/upper/common_enb.h +++ b/srsenb/hdr/upper/common_enb.h @@ -24,8 +24,8 @@ * */ -#ifndef COMMON_ENB_H -#define COMMON_ENB_H +#ifndef SRSENB_COMMON_ENB_H +#define SRSENB_COMMON_ENB_H /******************************************************************************* INCLUDES @@ -181,4 +181,4 @@ inline void uint16_to_uint8(uint16_t i, uint8_t *buf) } // namespace srsenb -#endif // COMMON_ENB_H +#endif // SRSENB_COMMON_ENB_H diff --git a/srsenb/hdr/upper/gtpu.h b/srsenb/hdr/upper/gtpu.h index 6958773b6..b3323ffe2 100644 --- a/srsenb/hdr/upper/gtpu.h +++ b/srsenb/hdr/upper/gtpu.h @@ -34,8 +34,8 @@ #include "srslte/srslte.h" #include "srslte/interfaces/enb_interfaces.h" -#ifndef GTPU_H -#define GTPU_H +#ifndef SRSENB_GTPU_H +#define SRSENB_GTPU_H namespace srsenb { @@ -127,4 +127,4 @@ private: } // namespace srsenb -#endif // GTPU_H +#endif // SRSENB_GTPU_H diff --git a/srsenb/hdr/upper/pdcp.h b/srsenb/hdr/upper/pdcp.h index 8c5b05275..45907e1f8 100644 --- a/srsenb/hdr/upper/pdcp.h +++ b/srsenb/hdr/upper/pdcp.h @@ -29,8 +29,8 @@ #include "srslte/interfaces/enb_interfaces.h" #include "srslte/upper/pdcp.h" -#ifndef PDCP_ENB_H -#define PDCP_ENB_H +#ifndef SRSENB_PDCP_H +#define SRSENB_PDCP_H namespace srsenb { @@ -113,4 +113,4 @@ private: } -#endif // PDCP_ENB_H +#endif // SRSENB_PDCP_H diff --git a/srsenb/hdr/upper/rlc.h b/srsenb/hdr/upper/rlc.h index b937cd216..98c3edfb3 100644 --- a/srsenb/hdr/upper/rlc.h +++ b/srsenb/hdr/upper/rlc.h @@ -29,8 +29,8 @@ #include "srslte/interfaces/enb_interfaces.h" #include "srslte/upper/rlc.h" -#ifndef RLC_ENB_H -#define RLC_ENB_H +#ifndef SRSENB_RLC_H +#define SRSENB_RLC_H namespace srsenb { @@ -96,4 +96,4 @@ private: } -#endif // RLC_H +#endif // SRSENB_RLC_H diff --git a/srsenb/hdr/upper/rrc.h b/srsenb/hdr/upper/rrc.h index 2935fd29f..49da1c0d9 100644 --- a/srsenb/hdr/upper/rrc.h +++ b/srsenb/hdr/upper/rrc.h @@ -24,8 +24,8 @@ * */ -#ifndef RRC_H -#define RRC_H +#ifndef SRSENB_RRC_H +#define SRSENB_RRC_H #include #include @@ -364,4 +364,4 @@ private: } // namespace srsenb -#endif // RRC_H +#endif // SRSENB_RRC_H diff --git a/srsenb/hdr/upper/rrc_metrics.h b/srsenb/hdr/upper/rrc_metrics.h index bce3ec95f..aba942f3f 100644 --- a/srsenb/hdr/upper/rrc_metrics.h +++ b/srsenb/hdr/upper/rrc_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef ENB_RRC_METRICS_H -#define ENB_RRC_METRICS_H +#ifndef SRSENB_RRC_METRICS_H +#define SRSENB_RRC_METRICS_H #include "upper/common_enb.h" @@ -55,4 +55,4 @@ struct rrc_metrics_t } // namespace srsenb -#endif // ENB_S1AP_METRICS_H +#endif // SRSENB_RRC_METRICS_H diff --git a/srsenb/hdr/upper/s1ap.h b/srsenb/hdr/upper/s1ap.h index 714035638..ad9137eec 100644 --- a/srsenb/hdr/upper/s1ap.h +++ b/srsenb/hdr/upper/s1ap.h @@ -24,8 +24,8 @@ * */ -#ifndef S1AP_H -#define S1AP_H +#ifndef SRSENB_S1AP_H +#define SRSENB_S1AP_H #include @@ -148,4 +148,4 @@ private: } // namespace srsenb -#endif // S1AP_H +#endif // SRSENB_S1AP_H diff --git a/srsenb/hdr/upper/s1ap_metrics.h b/srsenb/hdr/upper/s1ap_metrics.h index f77dc699c..b73b0afa0 100644 --- a/srsenb/hdr/upper/s1ap_metrics.h +++ b/srsenb/hdr/upper/s1ap_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef ENB_S1AP_METRICS_H -#define ENB_S1AP_METRICS_H +#ifndef SRSENB_S1AP_METRICS_H +#define SRSENB_S1AP_METRICS_H namespace srsenb { @@ -43,4 +43,4 @@ struct s1ap_metrics_t } // namespace srsenb -#endif // ENB_S1AP_METRICS_H +#endif // SRSENB_S1AP_METRICS_H diff --git a/srsepc/hdr/hss/hss.h b/srsepc/hdr/hss/hss.h index 818feae49..97e2d45c1 100644 --- a/srsepc/hdr/hss/hss.h +++ b/srsepc/hdr/hss/hss.h @@ -30,8 +30,8 @@ * interfaces and helpers. *****************************************************************************/ -#ifndef HSS_H -#define HSS_H +#ifndef SRSEPC_HSS_H +#define SRSEPC_HSS_H #include #include "srslte/common/log.h" @@ -124,4 +124,4 @@ private: } // namespace srsepc -#endif // MME_H +#endif // SRSEPC_HSS_H diff --git a/srsepc/hdr/mme/mme.h b/srsepc/hdr/mme/mme.h index c0eac0685..599059260 100644 --- a/srsepc/hdr/mme/mme.h +++ b/srsepc/hdr/mme/mme.h @@ -30,8 +30,8 @@ * interfaces and helpers. *****************************************************************************/ -#ifndef MME_H -#define MME_H +#ifndef SRSEPC_MME_H +#define SRSEPC_MME_H #include #include "srslte/common/log.h" @@ -89,4 +89,4 @@ private: } // namespace srsepc -#endif // MME_H +#endif // SRSEPC_MME_H diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index f41172cce..5f7ecc64c 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -23,8 +23,8 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef MME_GTPC_H -#define MME_GTPC_H +#ifndef SRSEPC_MME_GTPC_H +#define SRSEPC_MME_GTPC_H #include "srslte/common/log.h" #include "srslte/common/log_filter.h" @@ -78,4 +78,4 @@ private: }; } -#endif +#endif // SRSEPC_MME_GTPC_H diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 31ea68436..6f3c64d5c 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -23,8 +23,8 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef S1AP_H -#define S1AP_H +#ifndef SRSEPC_S1AP_H +#define SRSEPC_S1AP_H #include "srslte/asn1/gtpc.h" #include "srslte/asn1/liblte_s1ap.h" @@ -153,4 +153,4 @@ s1ap::get_plmn() } //namespace srsepc -#endif //S1AP_H +#endif // SRSEPC_S1AP_H diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index 9fea71d3f..a71daada8 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -18,8 +18,8 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef S1AP_COMMON_H -#define S1AP_COMMON_H +#ifndef SRSEPC_S1AP_COMMON_H +#define SRSEPC_S1AP_COMMON_H #include "srslte/common/security.h" #include "srslte/asn1/gtpc_ies.h" @@ -162,4 +162,5 @@ typedef struct{ erab_ctx_t erabs_ctx[MAX_ERABS_PER_UE]; } ue_ctx_t; }//namespace -#endif + +#endif // SRSEPC_S1AP_COMMON_H diff --git a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h index 6fc599101..31a4ce6ba 100644 --- a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h @@ -23,8 +23,8 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef S1AP_CTX_MNGMT_PROC_H -#define S1AP_CTX_MNGMT_PROC_H +#ifndef SRSEPC_S1AP_CTX_MNGMT_PROC_H +#define SRSEPC_S1AP_CTX_MNGMT_PROC_H #include "srslte/asn1/liblte_s1ap.h" #include "srslte/common/common.h" @@ -70,4 +70,4 @@ private: } //namespace srsepc -#endif //S1AP_MNGMT_PROC +#endif // SRSEPC_S1AP_CTX_MNGMT_PROC_H diff --git a/srsepc/hdr/mme/s1ap_mngmt_proc.h b/srsepc/hdr/mme/s1ap_mngmt_proc.h index 7f5771676..a8fd24df2 100644 --- a/srsepc/hdr/mme/s1ap_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_mngmt_proc.h @@ -23,8 +23,8 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef S1AP_MNGMT_PROC_H -#define S1AP_MNGMT_PROC_H +#ifndef SRSEPC_S1AP_MNGMT_PROC_H +#define SRSEPC_S1AP_MNGMT_PROC_H #include "srslte/asn1/liblte_s1ap.h" #include "srslte/common/common.h" @@ -65,4 +65,4 @@ private: } //namespace srsepc -#endif //S1AP_MNGMT_PROC +#endif // SRSEPC_S1AP_MNGMT_PROC_H diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index 500f41565..a3fc5cccc 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -23,8 +23,8 @@ * and at http://www.gnu.org/licenses/. * */ -#ifndef S1AP_NAS_TRANSPORT_H -#define S1AP_NAS_TRANSPORT_H +#ifndef SRSEPC_S1AP_NAS_TRANSPORT_H +#define SRSEPC_S1AP_NAS_TRANSPORT_H #include "srslte/asn1/liblte_s1ap.h" #include "srslte/common/buffer_pool.h" @@ -130,4 +130,4 @@ private: mme_gtpc* m_mme_gtpc; }; } //namespace srsepc -#endif //S1AP_NAS_TRANSPORT +#endif // SRSEPC_S1AP_NAS_TRANSPORT_H diff --git a/srsepc/hdr/spgw/spgw.h b/srsepc/hdr/spgw/spgw.h index e82d3f6ea..98ad59403 100644 --- a/srsepc/hdr/spgw/spgw.h +++ b/srsepc/hdr/spgw/spgw.h @@ -30,8 +30,8 @@ * interfaces and helpers. *****************************************************************************/ -#ifndef SPGW_H -#define SPGW_H +#ifndef SRSEPC_SPGW_H +#define SRSEPC_SPGW_H #include #include "srslte/common/log.h" @@ -135,4 +135,4 @@ private: } // namespace srsepc -#endif // SGW_H +#endif // SRSEPC_SPGW_H diff --git a/srsue/hdr/mac/demux.h b/srsue/hdr/mac/demux.h index fb38990ec..c738a0fd3 100644 --- a/srsue/hdr/mac/demux.h +++ b/srsue/hdr/mac/demux.h @@ -24,8 +24,8 @@ * */ -#ifndef DEMUX_H -#define DEMUX_H +#ifndef SRSUE_DEMUX_H +#define SRSUE_DEMUX_H #include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/pdu_queue.h" @@ -86,7 +86,7 @@ private: } // namespace srsue -#endif // DEMUX_H +#endif // SRSUE_DEMUX_H diff --git a/srsue/hdr/mac/dl_harq.h b/srsue/hdr/mac/dl_harq.h index cfdfdfc5f..c6f07251a 100644 --- a/srsue/hdr/mac/dl_harq.h +++ b/srsue/hdr/mac/dl_harq.h @@ -24,8 +24,8 @@ * */ -#ifndef DL_HARQ_H -#define DL_HARQ_H +#ifndef SRSUE_DL_HARQ_H +#define SRSUE_DL_HARQ_H #define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) @@ -447,4 +447,4 @@ private: } // namespace srsue -#endif // DL_HARQ_H +#endif // SRSUE_DL_HARQ_H diff --git a/srsue/hdr/mac/dl_sps.h b/srsue/hdr/mac/dl_sps.h index 8ec83cb52..dd6328fdc 100644 --- a/srsue/hdr/mac/dl_sps.h +++ b/srsue/hdr/mac/dl_sps.h @@ -24,8 +24,8 @@ * */ -#ifndef DL_SPS_H -#define DL_SPS_H +#ifndef SRSUE_DL_SPS_H +#define SRSUE_DL_SPS_H #include "srslte/common/log.h" #include "srslte/common/timers.h" @@ -50,4 +50,4 @@ private: } // namespace srsue -#endif // DL_SPS_H +#endif // SRSUE_DL_SPS_H diff --git a/srsue/hdr/mac/mac.h b/srsue/hdr/mac/mac.h index f4b0ffe3a..0e427a8a7 100644 --- a/srsue/hdr/mac/mac.h +++ b/srsue/hdr/mac/mac.h @@ -24,8 +24,8 @@ * */ -#ifndef MAC_H -#define MAC_H +#ifndef SRSUE_MAC_H +#define SRSUE_MAC_H #include "srslte/common/log.h" #include "mac/dl_harq.h" @@ -200,4 +200,4 @@ private: } // namespace srsue -#endif // MAC_H +#endif // SRSUE_MAC_H diff --git a/srsue/hdr/mac/mac_metrics.h b/srsue/hdr/mac/mac_metrics.h index 91ce29cab..a201d2a7f 100644 --- a/srsue/hdr/mac/mac_metrics.h +++ b/srsue/hdr/mac/mac_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef UE_MAC_METRICS_H -#define UE_MAC_METRICS_H +#ifndef SRSUE_MAC_METRICS_H +#define SRSUE_MAC_METRICS_H namespace srsue { @@ -43,4 +43,4 @@ struct mac_metrics_t } // namespace srsue -#endif // UE_MAC_METRICS_H +#endif // SRSUE_MAC_METRICS_H diff --git a/srsue/hdr/mac/mux.h b/srsue/hdr/mac/mux.h index 17a854711..04f7e302b 100644 --- a/srsue/hdr/mac/mux.h +++ b/srsue/hdr/mac/mux.h @@ -24,8 +24,8 @@ * */ -#ifndef MUX_H -#define MUX_H +#ifndef SRSUE_MUX_H +#define SRSUE_MUX_H #include @@ -114,5 +114,5 @@ private: } // namespace srsue -#endif // MUX_H +#endif // SRSUE_MUX_H diff --git a/srsue/hdr/mac/proc.h b/srsue/hdr/mac/proc.h index 3fa864cb0..f3601385d 100644 --- a/srsue/hdr/mac/proc.h +++ b/srsue/hdr/mac/proc.h @@ -24,8 +24,8 @@ * */ -#ifndef PROC_H -#define PROC_H +#ifndef SRSUE_PROC_H +#define SRSUE_PROC_H #include @@ -56,4 +56,4 @@ private: } // namespace srsue -#endif // PROC_H +#endif // SRSUE_PROC_H diff --git a/srsue/hdr/mac/proc_bsr.h b/srsue/hdr/mac/proc_bsr.h index 656e9a7a3..9592df667 100644 --- a/srsue/hdr/mac/proc_bsr.h +++ b/srsue/hdr/mac/proc_bsr.h @@ -24,8 +24,8 @@ * */ -#ifndef PROCBSR_H -#define PROCBSR_H +#ifndef SRSUE_PROC_BSR_H +#define SRSUE_PROC_BSR_H #include @@ -88,4 +88,4 @@ private: } // namespace srsue -#endif // PROCBSR_H +#endif // SRSUE_PROC_BSR_H diff --git a/srsue/hdr/mac/proc_phr.h b/srsue/hdr/mac/proc_phr.h index 240a7bab7..b12280220 100644 --- a/srsue/hdr/mac/proc_phr.h +++ b/srsue/hdr/mac/proc_phr.h @@ -24,8 +24,8 @@ * */ -#ifndef PROCPHR_H -#define PROCPHR_H +#ifndef SRSUE_PROC_PHR_H +#define SRSUE_PROC_PHR_H #include #include "srslte/common/timers.h" @@ -74,4 +74,4 @@ private: } // namespace srsue -#endif // PROCPHR_H +#endif // SRSUE_PROC_PHR_H diff --git a/srsue/hdr/mac/proc_ra.h b/srsue/hdr/mac/proc_ra.h index de8a0671d..9163b8530 100644 --- a/srsue/hdr/mac/proc_ra.h +++ b/srsue/hdr/mac/proc_ra.h @@ -24,8 +24,8 @@ * */ -#ifndef PROCRA_H -#define PROCRA_H +#ifndef SRSUE_PROC_RA_H +#define SRSUE_PROC_RA_H #include @@ -216,4 +216,4 @@ private: } // namespace srsue -#endif // PROCRA_H +#endif // SRSUE_PROC_RA_H diff --git a/srsue/hdr/mac/proc_sr.h b/srsue/hdr/mac/proc_sr.h index 9425481dd..878f92fb5 100644 --- a/srsue/hdr/mac/proc_sr.h +++ b/srsue/hdr/mac/proc_sr.h @@ -24,8 +24,8 @@ * */ -#ifndef PROCSR_H -#define PROCSR_H +#ifndef SRSUE_PROC_SR_H +#define SRSUE_PROC_SR_H #include #include "srslte/interfaces/ue_interfaces.h" @@ -64,4 +64,4 @@ private: } // namespace srsue -#endif // PROCSR_H +#endif // SRSUE_PROC_SR_H diff --git a/srsue/hdr/mac/ul_harq.h b/srsue/hdr/mac/ul_harq.h index ee9bc6279..034c09cf6 100644 --- a/srsue/hdr/mac/ul_harq.h +++ b/srsue/hdr/mac/ul_harq.h @@ -24,8 +24,8 @@ * */ -#ifndef ULHARQ_H -#define ULHARQ_H +#ifndef SRSUE_UL_HARQ_H +#define SRSUE_UL_HARQ_H #define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) @@ -429,4 +429,4 @@ private: } // namespace srsue -#endif // ULHARQ_H +#endif // SRSUE_UL_HARQ_H diff --git a/srsue/hdr/mac/ul_sps.h b/srsue/hdr/mac/ul_sps.h index 59af7f507..985b8470f 100644 --- a/srsue/hdr/mac/ul_sps.h +++ b/srsue/hdr/mac/ul_sps.h @@ -24,8 +24,8 @@ * */ -#ifndef ULSPS_H -#define ULSPS_H +#ifndef SRSUE_UL_SPS_H +#define SRSUE_UL_SPS_H #include "srslte/common/log.h" #include "srslte/common/timers.h" @@ -50,4 +50,4 @@ private: } // namespace srsue -#endif // ULSPS_H +#endif // SRSUE_UL_SPS_H diff --git a/srsue/hdr/metrics_csv.h b/srsue/hdr/metrics_csv.h index 72a9dc050..f07b0c119 100644 --- a/srsue/hdr/metrics_csv.h +++ b/srsue/hdr/metrics_csv.h @@ -29,8 +29,8 @@ * Description: Metrics class writing to CSV file. *****************************************************************************/ -#ifndef METRICS_CSV_H -#define METRICS_CSV_H +#ifndef SRSUE_METRICS_CSV_H +#define SRSUE_METRICS_CSV_H #include #include @@ -64,4 +64,4 @@ private: } // namespace srsue -#endif // METRICS_CSV_H +#endif // SRSUE_METRICS_CSV_H diff --git a/srsue/hdr/metrics_stdout.h b/srsue/hdr/metrics_stdout.h index 01f28f35e..2b0df9ca3 100644 --- a/srsue/hdr/metrics_stdout.h +++ b/srsue/hdr/metrics_stdout.h @@ -29,8 +29,8 @@ * Description: Metrics class printing to stdout. *****************************************************************************/ -#ifndef METRICS_STDOUT_H -#define METRICS_STDOUT_H +#ifndef SRSUE_METRICS_STDOUT_H +#define SRSUE_METRICS_STDOUT_H #include #include @@ -64,4 +64,4 @@ private: } // namespace srsue -#endif // METRICS_STDOUT_H +#endif // SRSUE_METRICS_STDOUT_H diff --git a/srsue/hdr/phy/phch_common.h b/srsue/hdr/phy/phch_common.h index f21738b6b..2f9b75569 100644 --- a/srsue/hdr/phy/phch_common.h +++ b/srsue/hdr/phy/phch_common.h @@ -24,8 +24,8 @@ * */ -#ifndef UEPHYWORKERCOMMON_H -#define UEPHYWORKERCOMMON_H +#ifndef SRSUE_PHCH_COMMON_H +#define SRSUE_PHCH_COMMON_H #define TX_MODE_CONTINUOUS 1 @@ -187,4 +187,4 @@ private: } // namespace srsue -#endif // UEPHYWORKERCOMMON_H +#endif // SRSUE_PDCH_COMMON_H diff --git a/srsue/hdr/phy/phch_recv.h b/srsue/hdr/phy/phch_recv.h index 378dfb8f9..7d3e2b25b 100644 --- a/srsue/hdr/phy/phch_recv.h +++ b/srsue/hdr/phy/phch_recv.h @@ -24,8 +24,8 @@ * */ -#ifndef UEPHYRECV_H -#define UEPHYRECV_H +#ifndef SRSUE_PHCH_RECV_H +#define SRSUE_PHCH_RECV_H #include @@ -340,4 +340,4 @@ private: } // namespace srsue -#endif // UEPHYRECV_H +#endif // SRSUE_PHCH_RECV_H diff --git a/srsue/hdr/phy/phch_worker.h b/srsue/hdr/phy/phch_worker.h index 28c4715ad..a5e2338c2 100644 --- a/srsue/hdr/phy/phch_worker.h +++ b/srsue/hdr/phy/phch_worker.h @@ -24,8 +24,8 @@ * */ -#ifndef UEPHYWORKER_H -#define UEPHYWORKER_H +#ifndef SRSUE_PHCH_WORKER_H +#define SRSUE_PHCH_WORKER_H #include #include "srslte/srslte.h" @@ -185,5 +185,5 @@ private: } // namespace srsue -#endif // UEPHYWORKER_H +#endif // SRSUE_PHCH_WORKER_H diff --git a/srsue/hdr/phy/phy.h b/srsue/hdr/phy/phy.h index 95140f8cd..1c03c4f87 100644 --- a/srsue/hdr/phy/phy.h +++ b/srsue/hdr/phy/phy.h @@ -24,8 +24,8 @@ * */ -#ifndef UEPHY_H -#define UEPHY_H +#ifndef SRSUE_PHY_H +#define SRSUE_PHY_H #include "srslte/srslte.h" #include "srslte/common/log_filter.h" @@ -187,4 +187,4 @@ private: } // namespace srsue -#endif // UEPHY_H +#endif // SRSUE_PHY_H diff --git a/srsue/hdr/phy/phy_metrics.h b/srsue/hdr/phy/phy_metrics.h index eafff2183..ce53c096c 100644 --- a/srsue/hdr/phy/phy_metrics.h +++ b/srsue/hdr/phy/phy_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef UE_PHY_METRICS_H -#define UE_PHY_METRICS_H +#ifndef SRSUE_PHY_METRICS_H +#define SRSUE_PHY_METRICS_H namespace srsue { @@ -65,4 +65,4 @@ struct phy_metrics_t } // namespace srsue -#endif // UE_PHY_METRICS_H +#endif // SRSUE_PHY_METRICS_H diff --git a/srsue/hdr/phy/prach.h b/srsue/hdr/phy/prach.h index 09be0c9b2..651203eb7 100644 --- a/srsue/hdr/phy/prach.h +++ b/srsue/hdr/phy/prach.h @@ -24,8 +24,8 @@ * */ -#ifndef UEPRACH_H -#define UEPRACH_H +#ifndef SRSUE_PRACH_H +#define SRSUE_PRACH_H #include @@ -87,4 +87,4 @@ namespace srsue { } // namespace srsue -#endif // UEPRACH_H +#endif // SRSUE_PRACH_H diff --git a/srsue/hdr/ue.h b/srsue/hdr/ue.h index 2aa7157e2..f66ac9fba 100644 --- a/srsue/hdr/ue.h +++ b/srsue/hdr/ue.h @@ -30,8 +30,8 @@ * layers and helpers. *****************************************************************************/ -#ifndef UE_H -#define UE_H +#ifndef SRSUE_UE_H +#define SRSUE_UE_H #include #include @@ -120,5 +120,5 @@ private: } // namespace srsue -#endif // UE_H +#endif // SRSUE_UE_H diff --git a/srsue/hdr/ue_base.h b/srsue/hdr/ue_base.h index 8e1a41478..802b7880d 100644 --- a/srsue/hdr/ue_base.h +++ b/srsue/hdr/ue_base.h @@ -29,8 +29,8 @@ * Description: Base class for UEs. *****************************************************************************/ -#ifndef UE_BASE_H -#define UE_BASE_H +#ifndef SRSUE_UE_BASE_H +#define SRSUE_UE_BASE_H #include #include @@ -183,5 +183,5 @@ private: } // namespace srsue -#endif // UE_BASE_H +#endif // SRSUE_UE_BASE_H diff --git a/srsue/hdr/ue_metrics_interface.h b/srsue/hdr/ue_metrics_interface.h index 20ee6f031..968b0de5a 100644 --- a/srsue/hdr/ue_metrics_interface.h +++ b/srsue/hdr/ue_metrics_interface.h @@ -24,8 +24,8 @@ * */ -#ifndef UE_METRICS_INTERFACE_H -#define UE_METRICS_INTERFACE_H +#ifndef SRSUE_UE_METRICS_INTERFACE_H +#define SRSUE_UE_METRICS_INTERFACE_H #include @@ -62,4 +62,4 @@ public: } // namespace srsue -#endif // UE_METRICS_INTERFACE_H +#endif // SRSUE_UE_METRICS_INTERFACE_H diff --git a/srsue/hdr/upper/gw.h b/srsue/hdr/upper/gw.h index aa5b2c70f..10ab50e56 100644 --- a/srsue/hdr/upper/gw.h +++ b/srsue/hdr/upper/gw.h @@ -24,8 +24,8 @@ * */ -#ifndef GW_H -#define GW_H +#ifndef SRSUE_GW_H +#define SRSUE_GW_H #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" @@ -94,4 +94,4 @@ private: } // namespace srsue -#endif // GW_H +#endif // SRSUE_GW_H diff --git a/srsue/hdr/upper/gw_metrics.h b/srsue/hdr/upper/gw_metrics.h index e596046c9..cce3af7ad 100644 --- a/srsue/hdr/upper/gw_metrics.h +++ b/srsue/hdr/upper/gw_metrics.h @@ -24,8 +24,8 @@ * */ -#ifndef UE_GW_METRICS_H -#define UE_GW_METRICS_H +#ifndef SRSUE_GW_METRICS_H +#define SRSUE_GW_METRICS_H namespace srsue { @@ -38,4 +38,4 @@ struct gw_metrics_t } // namespace srsue -#endif // UE_GW_METRICS_H +#endif // SRSUE_GW_METRICS_H diff --git a/srsue/hdr/upper/nas.h b/srsue/hdr/upper/nas.h index 8a1fd6ae3..5f431cc0a 100644 --- a/srsue/hdr/upper/nas.h +++ b/srsue/hdr/upper/nas.h @@ -24,8 +24,8 @@ * */ -#ifndef NAS_H -#define NAS_H +#ifndef SRSUE_NAS_H +#define SRSUE_NAS_H #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" @@ -220,4 +220,4 @@ private: } // namespace srsue -#endif // NAS_H +#endif // SRSUE_NAS_H diff --git a/srsue/hdr/upper/rrc.h b/srsue/hdr/upper/rrc.h index 5c9899eab..ba8fdd046 100644 --- a/srsue/hdr/upper/rrc.h +++ b/srsue/hdr/upper/rrc.h @@ -24,8 +24,8 @@ * */ -#ifndef RRC_H -#define RRC_H +#ifndef SRSUE_RRC_H +#define SRSUE_RRC_H #include "pthread.h" @@ -580,4 +580,4 @@ private: } // namespace srsue -#endif // RRC_H +#endif // SRSUE_RRC_H diff --git a/srsue/hdr/upper/rrc_common.h b/srsue/hdr/upper/rrc_common.h index 259d08fd7..912f39ddc 100644 --- a/srsue/hdr/upper/rrc_common.h +++ b/srsue/hdr/upper/rrc_common.h @@ -24,8 +24,8 @@ * */ -#ifndef RRC_COMMON_H -#define RRC_COMMON_H +#ifndef SRSUE_RRC_COMMON_H +#define SRSUE_RRC_COMMON_H namespace srsue { @@ -58,4 +58,4 @@ static const char rrc_state_text[RRC_STATE_N_ITEMS][100] = {"IDLE", } // namespace srsue -#endif // RRC_COMMON_H +#endif // SRSUE_RRC_COMMON_H diff --git a/srsue/hdr/upper/usim.h b/srsue/hdr/upper/usim.h index e37f58218..a5f703781 100644 --- a/srsue/hdr/upper/usim.h +++ b/srsue/hdr/upper/usim.h @@ -24,8 +24,8 @@ * */ -#ifndef USIM_H -#define USIM_H +#ifndef SRSUE_USIM_H +#define SRSUE_USIM_H #include #include "srslte/common/log.h" @@ -151,4 +151,4 @@ private: } // namespace srsue -#endif // USIM_H +#endif // SRSUE_USIM_H From 06d45592948acc5de3d14359792fd388c8bdff21 Mon Sep 17 00:00:00 2001 From: David Rupprecht Date: Sun, 1 Apr 2018 18:08:24 +0200 Subject: [PATCH 134/143] Change include path absolut to project dir --- .../srslte/interfaces/enb_metrics_interface.h | 12 ++++++------ srsenb/CMakeLists.txt | 2 +- srsenb/hdr/mac/mac.h | 6 +++--- srsenb/hdr/mac/scheduler_metric.h | 2 +- srsenb/hdr/mac/ue.h | 2 +- srsenb/hdr/phy/phch_worker.h | 2 +- srsenb/hdr/phy/phy.h | 6 +++--- srsenb/hdr/phy/txrx.h | 4 ++-- srsenb/hdr/upper/gtpu.h | 2 +- srsenb/hdr/upper/rrc.h | 2 +- srsenb/hdr/upper/rrc_metrics.h | 2 +- srsenb/hdr/upper/s1ap.h | 2 +- srsenb/src/enb.cc | 3 +-- srsenb/src/enb_cfg_parser.cc | 4 ++-- srsenb/src/enb_cfg_parser.h | 4 ++-- srsenb/src/mac/mac.cc | 2 +- srsenb/src/mac/scheduler.cc | 2 +- srsenb/src/mac/scheduler_harq.cc | 2 +- srsenb/src/mac/scheduler_metric.cc | 4 ++-- srsenb/src/mac/scheduler_ue.cc | 4 ++-- srsenb/src/mac/ue.cc | 2 +- srsenb/src/main.cc | 4 ++-- srsenb/src/metrics_stdout.cc | 2 +- srsenb/src/parser.cc | 2 +- srsenb/src/phy/phch_common.cc | 2 +- srsenb/src/phy/phch_worker.cc | 2 +- srsenb/src/phy/phy.cc | 2 +- srsenb/src/phy/prach_worker.cc | 2 +- srsenb/src/phy/txrx.cc | 4 ++-- srsenb/src/upper/gtpu.cc | 2 +- srsenb/src/upper/pdcp.cc | 4 ++-- srsenb/src/upper/rlc.cc | 4 ++-- srsenb/src/upper/rrc.cc | 3 +-- srsenb/src/upper/s1ap.cc | 4 ++-- srsenb/test/mac/scheduler_test.cc | 4 ++-- srsenb/test/upper/ip_test.cc | 4 ++-- srsenb/test/upper/plmn_test.cc | 2 +- srsepc/CMakeLists.txt | 2 +- srsepc/hdr/mme/mme_gtpc.h | 2 +- srsepc/hdr/mme/s1ap.h | 12 ++++++------ srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h | 4 ++-- srsepc/hdr/mme/s1ap_mngmt_proc.h | 2 +- srsepc/hdr/mme/s1ap_nas_transport.h | 6 +++--- srsepc/src/hss/hss.cc | 2 +- srsepc/src/main.cc | 6 +++--- srsepc/src/mme/mme.cc | 2 +- srsepc/src/mme/mme_gtpc.cc | 6 +++--- srsepc/src/mme/s1ap.cc | 2 +- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 4 ++-- srsepc/src/mme/s1ap_mngmt_proc.cc | 4 ++-- srsepc/src/mme/s1ap_nas_transport.cc | 4 ++-- srsepc/src/spgw/spgw.cc | 4 ++-- srsue/CMakeLists.txt | 2 +- srsue/hdr/mac/dl_harq.h | 4 ++-- srsue/hdr/mac/mac.h | 18 +++++++++--------- srsue/hdr/mac/mux.h | 4 ++-- srsue/hdr/mac/proc_ra.h | 4 ++-- srsue/hdr/mac/ul_harq.h | 4 ++-- srsue/hdr/phy/phch_common.h | 2 +- srsue/hdr/phy/phch_recv.h | 6 +++--- srsue/hdr/phy/phch_worker.h | 2 +- srsue/hdr/phy/phy.h | 10 +++++----- srsue/src/mac/demux.cc | 4 ++-- srsue/src/mac/mac.cc | 2 +- srsue/src/mac/mux.cc | 4 ++-- srsue/src/mac/proc_bsr.cc | 6 +++--- srsue/src/mac/proc_phr.cc | 6 +++--- srsue/src/mac/proc_ra.cc | 6 +++--- srsue/src/mac/proc_sr.cc | 2 +- srsue/src/main.cc | 6 +++--- srsue/src/metrics_csv.cc | 2 +- srsue/src/metrics_stdout.cc | 2 +- srsue/src/phy/phch_common.cc | 2 +- srsue/src/phy/phch_recv.cc | 4 ++-- srsue/src/phy/phch_worker.cc | 2 +- srsue/src/phy/phy.cc | 2 +- srsue/src/phy/prach.cc | 4 ++-- srsue/src/ue.cc | 2 +- srsue/src/ue_base.cc | 4 ++-- srsue/src/upper/gw.cc | 2 +- srsue/src/upper/nas.cc | 2 +- srsue/src/upper/rrc.cc | 2 +- srsue/src/upper/usim.cc | 2 +- srsue/test/mac/mac_test.cc | 4 ++-- srsue/test/metrics_test.cc | 6 +++--- srsue/test/phy/ue_itf_test_prach.cc | 2 +- srsue/test/phy/ue_itf_test_sib1.cc | 2 +- srsue/test/upper/ip_test.cc | 6 +++--- srsue/test/upper/nas_test.cc | 8 ++++---- srsue/test/upper/usim_test.cc | 2 +- 90 files changed, 166 insertions(+), 168 deletions(-) diff --git a/lib/include/srslte/interfaces/enb_metrics_interface.h b/lib/include/srslte/interfaces/enb_metrics_interface.h index 6c8b2e740..4e540ab78 100644 --- a/lib/include/srslte/interfaces/enb_metrics_interface.h +++ b/lib/include/srslte/interfaces/enb_metrics_interface.h @@ -29,13 +29,13 @@ #include -#include "upper/common_enb.h" -#include "upper/s1ap_metrics.h" -#include "upper/rrc_metrics.h" -#include "../../../../srsue/hdr/upper/gw_metrics.h" +#include "srsenb/hdr/upper/common_enb.h" +#include "srsenb/hdr/upper/s1ap_metrics.h" +#include "srsenb/hdr/upper/rrc_metrics.h" +#include "srsue/hdr/upper/gw_metrics.h" #include "srslte/upper/rlc_metrics.h" -#include "mac/mac_metrics.h" -#include "phy/phy_metrics.h" +#include "srsenb/hdr/mac/mac_metrics.h" +#include "srsenb/hdr/phy/phy_metrics.h" namespace srsenb { diff --git a/srsenb/CMakeLists.txt b/srsenb/CMakeLists.txt index c836f36d5..f36987915 100644 --- a/srsenb/CMakeLists.txt +++ b/srsenb/CMakeLists.txt @@ -35,7 +35,7 @@ endif() include_directories( ${Boost_INCLUDE_DIRS} ${SEC_INCLUDE_DIRS} - ${PROJECT_SOURCE_DIR}/srsenb/hdr + ${PROJECT_SOURCE_DIR} ) link_directories( diff --git a/srsenb/hdr/mac/mac.h b/srsenb/hdr/mac/mac.h index af122e36b..5f541b443 100644 --- a/srsenb/hdr/mac/mac.h +++ b/srsenb/hdr/mac/mac.h @@ -36,10 +36,10 @@ #include "srslte/common/threads.h" #include "srslte/common/tti_sync_cv.h" #include "srslte/common/mac_pcap.h" -#include "mac/scheduler.h" -#include "mac/scheduler_metric.h" +#include "scheduler.h" +#include "scheduler_metric.h" #include "srslte/interfaces/enb_metrics_interface.h" -#include "mac/ue.h" +#include "ue.h" namespace srsenb { diff --git a/srsenb/hdr/mac/scheduler_metric.h b/srsenb/hdr/mac/scheduler_metric.h index 385d5803d..11e77b455 100644 --- a/srsenb/hdr/mac/scheduler_metric.h +++ b/srsenb/hdr/mac/scheduler_metric.h @@ -27,7 +27,7 @@ #ifndef SRSENB_SCHEDULER_METRIC_H #define SRSENB_SCHEDULER_METRIC_H -#include "mac/scheduler.h" +#include "scheduler.h" namespace srsenb { diff --git a/srsenb/hdr/mac/ue.h b/srsenb/hdr/mac/ue.h index 405acd120..e7fbd0c10 100644 --- a/srsenb/hdr/mac/ue.h +++ b/srsenb/hdr/mac/ue.h @@ -34,7 +34,7 @@ #include "srslte/interfaces/enb_interfaces.h" #include "srslte/interfaces/sched_interface.h" #include -#include "mac/mac_metrics.h" +#include "mac_metrics.h" namespace srsenb { diff --git a/srsenb/hdr/phy/phch_worker.h b/srsenb/hdr/phy/phch_worker.h index 35e0607ba..9821a2d1e 100644 --- a/srsenb/hdr/phy/phch_worker.h +++ b/srsenb/hdr/phy/phch_worker.h @@ -30,7 +30,7 @@ #include #include "srslte/srslte.h" -#include "phy/phch_common.h" +#include "phch_common.h" #define LOG_EXECTIME diff --git a/srsenb/hdr/phy/phy.h b/srsenb/hdr/phy/phy.h index 07c181741..74b28be11 100644 --- a/srsenb/hdr/phy/phy.h +++ b/srsenb/hdr/phy/phy.h @@ -29,9 +29,9 @@ #include "srslte/common/log.h" #include "srslte/common/log_filter.h" -#include "phy/txrx.h" -#include "phy/phch_worker.h" -#include "phy/phch_common.h" +#include "txrx.h" +#include "phch_worker.h" +#include "phch_common.h" #include "srslte/radio/radio.h" #include "srslte/interfaces/enb_interfaces.h" #include "srslte/common/task_dispatcher.h" diff --git a/srsenb/hdr/phy/txrx.h b/srsenb/hdr/phy/txrx.h index 9ba048c83..69a119900 100644 --- a/srsenb/hdr/phy/txrx.h +++ b/srsenb/hdr/phy/txrx.h @@ -31,8 +31,8 @@ #include "srslte/common/threads.h" #include "srslte/common/thread_pool.h" #include "srslte/radio/radio.h" -#include "phy/phch_common.h" -#include "phy/prach_worker.h" +#include "phch_common.h" +#include "prach_worker.h" namespace srsenb { diff --git a/srsenb/hdr/upper/gtpu.h b/srsenb/hdr/upper/gtpu.h index b3323ffe2..892068757 100644 --- a/srsenb/hdr/upper/gtpu.h +++ b/srsenb/hdr/upper/gtpu.h @@ -29,7 +29,7 @@ #include "srslte/common/buffer_pool.h" #include "srslte/common/log.h" -#include "upper/common_enb.h" +#include "common_enb.h" #include "srslte/common/threads.h" #include "srslte/srslte.h" #include "srslte/interfaces/enb_interfaces.h" diff --git a/srsenb/hdr/upper/rrc.h b/srsenb/hdr/upper/rrc.h index 49da1c0d9..cadb4af43 100644 --- a/srsenb/hdr/upper/rrc.h +++ b/srsenb/hdr/upper/rrc.h @@ -36,7 +36,7 @@ #include "srslte/common/timeout.h" #include "srslte/common/log.h" #include "srslte/interfaces/enb_interfaces.h" -#include "upper/common_enb.h" +#include "common_enb.h" #include "rrc_metrics.h" namespace srsenb { diff --git a/srsenb/hdr/upper/rrc_metrics.h b/srsenb/hdr/upper/rrc_metrics.h index aba942f3f..7c388da01 100644 --- a/srsenb/hdr/upper/rrc_metrics.h +++ b/srsenb/hdr/upper/rrc_metrics.h @@ -27,7 +27,7 @@ #ifndef SRSENB_RRC_METRICS_H #define SRSENB_RRC_METRICS_H -#include "upper/common_enb.h" +#include "common_enb.h" namespace srsenb { diff --git a/srsenb/hdr/upper/s1ap.h b/srsenb/hdr/upper/s1ap.h index ad9137eec..35369790f 100644 --- a/srsenb/hdr/upper/s1ap.h +++ b/srsenb/hdr/upper/s1ap.h @@ -35,7 +35,7 @@ #include "srslte/common/msg_queue.h" #include "srslte/common/threads.h" #include "srslte/interfaces/enb_interfaces.h" -#include "upper/common_enb.h" +#include "common_enb.h" #include "srslte/asn1/liblte_s1ap.h" #include "s1ap_metrics.h" diff --git a/srsenb/src/enb.cc b/srsenb/src/enb.cc index 2d3466522..85cda6185 100644 --- a/srsenb/src/enb.cc +++ b/srsenb/src/enb.cc @@ -25,8 +25,7 @@ */ #include -#include -#include "enb.h" +#include "srsenb/hdr/enb.h" namespace srsenb { diff --git a/srsenb/src/enb_cfg_parser.cc b/srsenb/src/enb_cfg_parser.cc index b63c46058..af2ade941 100644 --- a/srsenb/src/enb_cfg_parser.cc +++ b/srsenb/src/enb_cfg_parser.cc @@ -26,10 +26,10 @@ #include "srslte/asn1/liblte_common.h" #include "srslte/asn1/liblte_rrc.h" -#include "cfg_parser.h" +#include "srsenb/hdr/cfg_parser.h" #include "srslte/srslte.h" -#include "parser.h" +#include "srsenb/hdr/parser.h" #include "enb_cfg_parser.h" namespace srsenb { diff --git a/srsenb/src/enb_cfg_parser.h b/srsenb/src/enb_cfg_parser.h index d68fb87d8..912c9bf19 100644 --- a/srsenb/src/enb_cfg_parser.h +++ b/srsenb/src/enb_cfg_parser.h @@ -33,9 +33,9 @@ #include #include #include -#include "parser.h" +#include "srsenb/hdr/parser.h" -#include "upper/rrc.h" +#include "srsenb/hdr/upper/rrc.h" #include "srslte/asn1/liblte_rrc.h" namespace srsenb { diff --git a/srsenb/src/mac/mac.cc b/srsenb/src/mac/mac.cc index 8b76cc4f3..463da2e25 100644 --- a/srsenb/src/mac/mac.cc +++ b/srsenb/src/mac/mac.cc @@ -36,7 +36,7 @@ #include #include "srslte/common/log.h" -#include "mac/mac.h" +#include "srsenb/hdr/mac/mac.h" //#define WRITE_SIB_PCAP diff --git a/srsenb/src/mac/scheduler.cc b/srsenb/src/mac/scheduler.cc index 2e0504193..53b3cd939 100644 --- a/srsenb/src/mac/scheduler.cc +++ b/srsenb/src/mac/scheduler.cc @@ -28,7 +28,7 @@ #include "srslte/srslte.h" #include "srslte/common/pdu.h" -#include "mac/scheduler.h" +#include "srsenb/hdr/mac/scheduler.h" #define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsenb/src/mac/scheduler_harq.cc b/srsenb/src/mac/scheduler_harq.cc index ad7986436..c860c7a14 100644 --- a/srsenb/src/mac/scheduler_harq.cc +++ b/srsenb/src/mac/scheduler_harq.cc @@ -28,7 +28,7 @@ #include "srslte/srslte.h" #include "srslte/common/pdu.h" -#include "mac/scheduler.h" +#include "srsenb/hdr/mac/scheduler.h" #define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsenb/src/mac/scheduler_metric.cc b/srsenb/src/mac/scheduler_metric.cc index 1d9cdb954..a15faebbd 100644 --- a/srsenb/src/mac/scheduler_metric.cc +++ b/srsenb/src/mac/scheduler_metric.cc @@ -25,8 +25,8 @@ */ #include -#include "mac/scheduler_harq.h" -#include "mac/scheduler_metric.h" +#include "srsenb/hdr/mac/scheduler_harq.h" +#include "srsenb/hdr/mac/scheduler_metric.h" #define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsenb/src/mac/scheduler_ue.cc b/srsenb/src/mac/scheduler_ue.cc index 6948f922a..6cb4462e8 100644 --- a/srsenb/src/mac/scheduler_ue.cc +++ b/srsenb/src/mac/scheduler_ue.cc @@ -28,8 +28,8 @@ #include "srslte/srslte.h" #include "srslte/common/pdu.h" -#include "mac/scheduler_ue.h" -#include "mac/scheduler.h" +#include "srsenb/hdr/mac/scheduler_ue.h" +#include "srsenb/hdr/mac/scheduler.h" #define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsenb/src/mac/ue.cc b/srsenb/src/mac/ue.cc index d6fe07d0a..39e8c88e2 100644 --- a/srsenb/src/mac/ue.cc +++ b/srsenb/src/mac/ue.cc @@ -28,7 +28,7 @@ #include #include "srslte/interfaces/enb_interfaces.h" -#include "mac/ue.h" +#include "srsenb/hdr/mac/ue.h" #define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsenb/src/main.cc b/srsenb/src/main.cc index 3aedda25a..45dd028b0 100644 --- a/srsenb/src/main.cc +++ b/srsenb/src/main.cc @@ -36,8 +36,8 @@ #include #include -#include "enb.h" -#include "metrics_stdout.h" +#include "srsenb/hdr/enb.h" +#include "srsenb/hdr/metrics_stdout.h" using namespace std; using namespace srsenb; diff --git a/srsenb/src/metrics_stdout.cc b/srsenb/src/metrics_stdout.cc index 5687f25e1..ca9137a24 100644 --- a/srsenb/src/metrics_stdout.cc +++ b/srsenb/src/metrics_stdout.cc @@ -24,7 +24,7 @@ * */ -#include "metrics_stdout.h" +#include "srsenb/hdr/metrics_stdout.h" #include #include diff --git a/srsenb/src/parser.cc b/srsenb/src/parser.cc index 82e088ab2..8a85789e9 100644 --- a/srsenb/src/parser.cc +++ b/srsenb/src/parser.cc @@ -24,7 +24,7 @@ * */ -#include "parser.h" +#include "srsenb/hdr/parser.h" #include namespace srsenb { diff --git a/srsenb/src/phy/phch_common.cc b/srsenb/src/phy/phch_common.cc index 99bfc3d29..ce8026ca5 100644 --- a/srsenb/src/phy/phch_common.cc +++ b/srsenb/src/phy/phch_common.cc @@ -27,7 +27,7 @@ #include "srslte/common/threads.h" #include "srslte/common/log.h" -#include "phy/txrx.h" +#include "srsenb/hdr/phy/txrx.h" #include diff --git a/srsenb/src/phy/phch_worker.cc b/srsenb/src/phy/phch_worker.cc index 5524be442..7ae174502 100644 --- a/srsenb/src/phy/phch_worker.cc +++ b/srsenb/src/phy/phch_worker.cc @@ -29,7 +29,7 @@ #include "srslte/common/threads.h" #include "srslte/common/log.h" -#include "phy/phch_worker.h" +#include "srsenb/hdr/phy/phch_worker.h" #define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsenb/src/phy/phy.cc b/srsenb/src/phy/phy.cc index 08b89d77f..120a3c7b5 100644 --- a/srsenb/src/phy/phy.cc +++ b/srsenb/src/phy/phy.cc @@ -34,7 +34,7 @@ #include "srslte/common/threads.h" #include "srslte/common/log.h" -#include "phy/phy.h" +#include "srsenb/hdr/phy/phy.h" #define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsenb/src/phy/prach_worker.cc b/srsenb/src/phy/prach_worker.cc index b4bd7da3f..a42849bbe 100644 --- a/srsenb/src/phy/prach_worker.cc +++ b/srsenb/src/phy/prach_worker.cc @@ -25,7 +25,7 @@ */ #include "srslte/srslte.h" -#include "phy/prach_worker.h" +#include "srsenb/hdr/phy/prach_worker.h" namespace srsenb { diff --git a/srsenb/src/phy/txrx.cc b/srsenb/src/phy/txrx.cc index 32c8aea00..7f6503b06 100644 --- a/srsenb/src/phy/txrx.cc +++ b/srsenb/src/phy/txrx.cc @@ -29,8 +29,8 @@ #include "srslte/common/threads.h" #include "srslte/common/log.h" -#include "phy/txrx.h" -#include "phy/phch_worker.h" +#include "srsenb/hdr/phy/txrx.h" +#include "srsenb/hdr/phy/phch_worker.h" #define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsenb/src/upper/gtpu.cc b/srsenb/src/upper/gtpu.cc index 2336f9047..0b0df8de2 100644 --- a/srsenb/src/upper/gtpu.cc +++ b/srsenb/src/upper/gtpu.cc @@ -24,7 +24,7 @@ * */ -#include "upper/gtpu.h" +#include "srsenb/hdr/upper/gtpu.h" #include #include #include diff --git a/srsenb/src/upper/pdcp.cc b/srsenb/src/upper/pdcp.cc index d3ed88c4e..99289ec4d 100644 --- a/srsenb/src/upper/pdcp.cc +++ b/srsenb/src/upper/pdcp.cc @@ -24,8 +24,8 @@ * */ -#include "upper/pdcp.h" -#include "upper/common_enb.h" +#include "srsenb/hdr/upper/pdcp.h" +#include "srsenb/hdr/upper/common_enb.h" namespace srsenb { diff --git a/srsenb/src/upper/rlc.cc b/srsenb/src/upper/rlc.cc index 0b7babbac..72d269c6c 100644 --- a/srsenb/src/upper/rlc.cc +++ b/srsenb/src/upper/rlc.cc @@ -24,8 +24,8 @@ * */ -#include "upper/rlc.h" -#include "upper/common_enb.h" +#include "srsenb/hdr/upper/rlc.h" +#include "srsenb/hdr/upper/common_enb.h" namespace srsenb { diff --git a/srsenb/src/upper/rrc.cc b/srsenb/src/upper/rrc.cc index 9fe1773f7..f47656c6d 100644 --- a/srsenb/src/upper/rrc.cc +++ b/srsenb/src/upper/rrc.cc @@ -26,10 +26,9 @@ #include "srslte/interfaces/sched_interface.h" #include "srslte/asn1/liblte_rrc.h" -#include "upper/rrc.h" +#include "srsenb/hdr/upper/rrc.h" #include "srslte/srslte.h" #include "srslte/asn1/liblte_mme.h" -#include "upper/rrc.h" using srslte::byte_buffer_t; using srslte::bit_buffer_t; diff --git a/srsenb/src/upper/s1ap.cc b/srsenb/src/upper/s1ap.cc index a3d937a57..b48e8a248 100644 --- a/srsenb/src/upper/s1ap.cc +++ b/srsenb/src/upper/s1ap.cc @@ -24,8 +24,8 @@ * */ -#include "upper/s1ap.h" -#include "upper/common_enb.h" +#include "srsenb/hdr/upper/s1ap.h" +#include "srsenb/hdr/upper/common_enb.h" #include #include diff --git a/srsenb/test/mac/scheduler_test.cc b/srsenb/test/mac/scheduler_test.cc index 73dd531b0..50d4cb409 100644 --- a/srsenb/test/mac/scheduler_test.cc +++ b/srsenb/test/mac/scheduler_test.cc @@ -26,8 +26,8 @@ #include -#include "mac/mac.h" -#include "phy/phy.h" +#include "srsenb/hdr/mac/mac.h" +#include "srsenb/hdr/phy/phy.h" #include "srslte/interfaces/enb_interfaces.h" #include "srslte/interfaces/sched_interface.h" diff --git a/srsenb/test/upper/ip_test.cc b/srsenb/test/upper/ip_test.cc index 8052ed4d7..9361a9901 100644 --- a/srsenb/test/upper/ip_test.cc +++ b/srsenb/test/upper/ip_test.cc @@ -36,8 +36,8 @@ #include #include -#include "mac/mac.h" -#include "phy/phy.h" +#include "srsenb/hdr/mac/mac.h" +#include "srsenb/hdr/phy/phy.h" #include "srslte/common/threads.h" #include "srslte/interfaces/enb_interfaces.h" #include "srslte/common/common.h" diff --git a/srsenb/test/upper/plmn_test.cc b/srsenb/test/upper/plmn_test.cc index ddf68d130..c8e9bdd69 100644 --- a/srsenb/test/upper/plmn_test.cc +++ b/srsenb/test/upper/plmn_test.cc @@ -8,7 +8,7 @@ */ #include -#include "upper/common_enb.h" +#include "srsenb/hdr/upper/common_enb.h" #include "srslte/asn1/liblte_rrc.h" void rrc_plmn_test() diff --git a/srsepc/CMakeLists.txt b/srsepc/CMakeLists.txt index 0006e5191..2b54d4a1e 100644 --- a/srsepc/CMakeLists.txt +++ b/srsepc/CMakeLists.txt @@ -35,7 +35,7 @@ endif() include_directories( ${Boost_INCLUDE_DIRS} ${SEC_INCLUDE_DIRS} - ${PROJECT_SOURCE_DIR}/srsepc/hdr + ${PROJECT_SOURCE_DIR} ) link_directories( diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index 5f7ecc64c..ad2181c85 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -30,7 +30,7 @@ #include "srslte/common/log_filter.h" #include "srslte/common/buffer_pool.h" #include "srslte/asn1/gtpc.h" -#include "mme/s1ap_common.h" +#include "s1ap_common.h" namespace srsepc { diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 6f3c64d5c..5036c18cd 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -40,12 +40,12 @@ #include #include #include -#include "mme/s1ap_common.h" -#include "mme/s1ap_mngmt_proc.h" -#include "mme/s1ap_nas_transport.h" -#include "mme/s1ap_ctx_mngmt_proc.h" -#include "mme/mme_gtpc.h" -#include "hss/hss.h" +#include "s1ap_common.h" +#include "s1ap_mngmt_proc.h" +#include "s1ap_nas_transport.h" +#include "s1ap_ctx_mngmt_proc.h" +#include "mme_gtpc.h" +#include "srsepc/hdr/hss/hss.h" namespace srsepc{ diff --git a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h index 31a4ce6ba..e6182269f 100644 --- a/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h @@ -28,9 +28,9 @@ #include "srslte/asn1/liblte_s1ap.h" #include "srslte/common/common.h" -#include "mme/s1ap_common.h" +#include "s1ap_common.h" #include "srslte/common/log_filter.h" -#include "mme/mme_gtpc.h" +#include "mme_gtpc.h" #include "srslte/common/buffer_pool.h" namespace srsepc{ diff --git a/srsepc/hdr/mme/s1ap_mngmt_proc.h b/srsepc/hdr/mme/s1ap_mngmt_proc.h index a8fd24df2..859a647e4 100644 --- a/srsepc/hdr/mme/s1ap_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_mngmt_proc.h @@ -28,7 +28,7 @@ #include "srslte/asn1/liblte_s1ap.h" #include "srslte/common/common.h" -#include "mme/s1ap_common.h" +#include "s1ap_common.h" #include "srslte/common/log_filter.h" namespace srsepc{ diff --git a/srsepc/hdr/mme/s1ap_nas_transport.h b/srsepc/hdr/mme/s1ap_nas_transport.h index a3fc5cccc..9df615914 100644 --- a/srsepc/hdr/mme/s1ap_nas_transport.h +++ b/srsepc/hdr/mme/s1ap_nas_transport.h @@ -28,10 +28,10 @@ #include "srslte/asn1/liblte_s1ap.h" #include "srslte/common/buffer_pool.h" -#include "mme/s1ap_common.h" +#include "s1ap_common.h" #include "srslte/asn1/gtpc.h" -#include "hss/hss.h" -#include "mme/mme_gtpc.h" +#include "srsepc/hdr/hss/hss.h" +#include "mme_gtpc.h" namespace srsepc{ diff --git a/srsepc/src/hss/hss.cc b/srsepc/src/hss/hss.cc index 703928270..d9a55960b 100644 --- a/srsepc/src/hss/hss.cc +++ b/srsepc/src/hss/hss.cc @@ -28,7 +28,7 @@ #include #include #include -#include "hss/hss.h" +#include "srsepc/hdr/hss/hss.h" #include "srslte/common/security.h" using namespace srslte; diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index 539b1b245..e2c006750 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -28,9 +28,9 @@ #include #include #include "srslte/common/bcd_helpers.h" -#include "mme/mme.h" -#include "hss/hss.h" -#include "spgw/spgw.h" +#include "srsepc/hdr/mme/mme.h" +#include "srsepc/hdr/hss/hss.h" +#include "srsepc/hdr/spgw/spgw.h" using namespace std; using namespace srsepc; diff --git a/srsepc/src/mme/mme.cc b/srsepc/src/mme/mme.cc index 4c63b5f6a..1a385d8dc 100644 --- a/srsepc/src/mme/mme.cc +++ b/srsepc/src/mme/mme.cc @@ -29,7 +29,7 @@ #include #include #include -#include "mme/mme.h" +#include "srsepc/hdr/mme/mme.h" namespace srsepc{ diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index e25ea05d1..1f53338c0 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -26,9 +26,9 @@ #include #include "srslte/asn1/gtpc.h" -#include "mme/mme_gtpc.h" -#include "mme/s1ap.h" -#include "spgw/spgw.h" +#include "srsepc/hdr/mme/mme_gtpc.h" +#include "srsepc/hdr/mme/s1ap.h" +#include "srsepc/hdr/spgw/spgw.h" namespace srsepc{ diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 0dce45c41..639725ee5 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -27,7 +27,7 @@ #include #include #include "srslte/common/bcd_helpers.h" -#include "mme/s1ap.h" +#include "srsepc/hdr/mme/s1ap.h" #include "srslte/asn1/gtpc.h" #include "srslte/common/liblte_security.h" diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 2938b128c..5500fa561 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -26,8 +26,8 @@ //#include "srslte/upper/s1ap_common.h" #include "srslte/common/bcd_helpers.h" -#include "mme/s1ap.h" -#include "mme/s1ap_ctx_mngmt_proc.h" +#include "srsepc/hdr/mme/s1ap.h" +#include "srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h" #include "srslte/common/liblte_security.h" diff --git a/srsepc/src/mme/s1ap_mngmt_proc.cc b/srsepc/src/mme/s1ap_mngmt_proc.cc index 4d4b16528..079eca100 100644 --- a/srsepc/src/mme/s1ap_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_mngmt_proc.cc @@ -26,8 +26,8 @@ //#include "srslte/upper/s1ap_common.h" #include "srslte/common/bcd_helpers.h" -#include "mme/s1ap.h" -#include "mme/s1ap_mngmt_proc.h" +#include "srsepc/hdr/mme/s1ap.h" +#include "srsepc/hdr/mme/s1ap_mngmt_proc.h" namespace srsepc{ diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 183815fc6..687ced63b 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -27,8 +27,8 @@ #include #include #include // for printing uint64_t -#include "mme/s1ap.h" -#include "mme/s1ap_nas_transport.h" +#include "srsepc/hdr/mme/s1ap.h" +#include "srsepc/hdr/mme/s1ap_nas_transport.h" #include "srslte/common/security.h" #include "srslte/common/liblte_security.h" diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index 1ef33a8f0..eec7bb4ec 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -33,8 +33,8 @@ #include #include #include -#include "spgw/spgw.h" -#include "mme/mme_gtpc.h" +#include "srsepc/hdr/spgw/spgw.h" +#include "srsepc/hdr/mme/mme_gtpc.h" #include "srslte/upper/gtpu.h" namespace srsepc{ diff --git a/srsue/CMakeLists.txt b/srsue/CMakeLists.txt index 85f391d6b..07a5f6b8f 100644 --- a/srsue/CMakeLists.txt +++ b/srsue/CMakeLists.txt @@ -31,7 +31,7 @@ endif() include_directories( ${Boost_INCLUDE_DIRS} ${SEC_INCLUDE_DIRS} - ${PROJECT_SOURCE_DIR}/srsue/hdr + ${PROJECT_SOURCE_DIR} ) link_directories( diff --git a/srsue/hdr/mac/dl_harq.h b/srsue/hdr/mac/dl_harq.h index c6f07251a..37eadad91 100644 --- a/srsue/hdr/mac/dl_harq.h +++ b/srsue/hdr/mac/dl_harq.h @@ -34,8 +34,8 @@ #include "srslte/common/log.h" #include "srslte/common/timers.h" -#include "mac/demux.h" -#include "mac/dl_sps.h" +#include "demux.h" +#include "dl_sps.h" #include "srslte/common/mac_pcap.h" #include "srslte/interfaces/ue_interfaces.h" diff --git a/srsue/hdr/mac/mac.h b/srsue/hdr/mac/mac.h index 0e427a8a7..7b119c27b 100644 --- a/srsue/hdr/mac/mac.h +++ b/srsue/hdr/mac/mac.h @@ -28,16 +28,16 @@ #define SRSUE_MAC_H #include "srslte/common/log.h" -#include "mac/dl_harq.h" -#include "mac/ul_harq.h" +#include "dl_harq.h" +#include "ul_harq.h" #include "srslte/common/timers.h" -#include "mac/mac_metrics.h" -#include "mac/proc_ra.h" -#include "mac/proc_sr.h" -#include "mac/proc_bsr.h" -#include "mac/proc_phr.h" -#include "mac/mux.h" -#include "mac/demux.h" +#include "mac_metrics.h" +#include "proc_ra.h" +#include "proc_sr.h" +#include "proc_bsr.h" +#include "proc_phr.h" +#include "mux.h" +#include "demux.h" #include "srslte/common/mac_pcap.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/tti_sync_cv.h" diff --git a/srsue/hdr/mac/mux.h b/srsue/hdr/mac/mux.h index 04f7e302b..2e621360f 100644 --- a/srsue/hdr/mac/mux.h +++ b/srsue/hdr/mac/mux.h @@ -34,8 +34,8 @@ #include "srslte/common/log.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/pdu.h" -#include "mac/proc_bsr.h" -#include "mac/proc_phr.h" +#include "proc_bsr.h" +#include "proc_phr.h" /* Logical Channel Multiplexing and Prioritization + Msg3 Buffer */ diff --git a/srsue/hdr/mac/proc_ra.h b/srsue/hdr/mac/proc_ra.h index 9163b8530..833173b75 100644 --- a/srsue/hdr/mac/proc_ra.h +++ b/srsue/hdr/mac/proc_ra.h @@ -31,8 +31,8 @@ #include "srslte/common/log.h" #include "srslte/common/timers.h" -#include "mac/mux.h" -#include "mac/demux.h" +#include "mux.h" +#include "demux.h" #include "srslte/common/pdu.h" #include "srslte/common/mac_pcap.h" diff --git a/srsue/hdr/mac/ul_harq.h b/srsue/hdr/mac/ul_harq.h index 034c09cf6..6fb27be8a 100644 --- a/srsue/hdr/mac/ul_harq.h +++ b/srsue/hdr/mac/ul_harq.h @@ -34,8 +34,8 @@ #include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/log.h" -#include "mac/mux.h" -#include "mac/ul_sps.h" +#include "mux.h" +#include "ul_sps.h" #include "srslte/common/mac_pcap.h" #include "srslte/common/timers.h" #include "srslte/common/interfaces_common.h" diff --git a/srsue/hdr/phy/phch_common.h b/srsue/hdr/phy/phch_common.h index 2f9b75569..c9a1cd6a1 100644 --- a/srsue/hdr/phy/phch_common.h +++ b/srsue/hdr/phy/phch_common.h @@ -37,7 +37,7 @@ #include "srslte/interfaces/ue_interfaces.h" #include "srslte/radio/radio.h" #include "srslte/common/log.h" -#include "phy/phy_metrics.h" +#include "phy_metrics.h" namespace srsue { diff --git a/srsue/hdr/phy/phch_recv.h b/srsue/hdr/phy/phch_recv.h index 7d3e2b25b..f18f52833 100644 --- a/srsue/hdr/phy/phch_recv.h +++ b/srsue/hdr/phy/phch_recv.h @@ -35,9 +35,9 @@ #include "srslte/common/thread_pool.h" #include "srslte/common/tti_sync_cv.h" #include "srslte/radio/radio_multi.h" -#include "phy/prach.h" -#include "phy/phch_worker.h" -#include "phy/phch_common.h" +#include "prach.h" +#include "phch_worker.h" +#include "phch_common.h" #include "srslte/interfaces/ue_interfaces.h" namespace srsue { diff --git a/srsue/hdr/phy/phch_worker.h b/srsue/hdr/phy/phch_worker.h index a5e2338c2..53848905b 100644 --- a/srsue/hdr/phy/phch_worker.h +++ b/srsue/hdr/phy/phch_worker.h @@ -31,7 +31,7 @@ #include "srslte/srslte.h" #include "srslte/common/thread_pool.h" #include "srslte/common/trace.h" -#include "phy/phch_common.h" +#include "phch_common.h" #define LOG_EXECTIME diff --git a/srsue/hdr/phy/phy.h b/srsue/hdr/phy/phy.h index 1c03c4f87..828a6b7e1 100644 --- a/srsue/hdr/phy/phy.h +++ b/srsue/hdr/phy/phy.h @@ -29,11 +29,11 @@ #include "srslte/srslte.h" #include "srslte/common/log_filter.h" -#include "phy/phy_metrics.h" -#include "phy/phch_recv.h" -#include "phy/prach.h" -#include "phy/phch_worker.h" -#include "phy/phch_common.h" +#include "phy_metrics.h" +#include "phch_recv.h" +#include "prach.h" +#include "phch_worker.h" +#include "phch_common.h" #include "srslte/radio/radio.h" #include "srslte/common/task_dispatcher.h" #include "srslte/common/trace.h" diff --git a/srsue/src/mac/demux.cc b/srsue/src/mac/demux.cc index 3ddd98b69..3e0d2f44f 100644 --- a/srsue/src/mac/demux.cc +++ b/srsue/src/mac/demux.cc @@ -30,8 +30,8 @@ #define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) #define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) -#include "mac/mac.h" -#include "mac/demux.h" +#include "srsue/hdr/mac/mac.h" +#include "srsue/hdr/mac/demux.h" #include "srslte/interfaces/ue_interfaces.h" namespace srsue { diff --git a/srsue/src/mac/mac.cc b/srsue/src/mac/mac.cc index 2531faafc..4033df888 100644 --- a/srsue/src/mac/mac.cc +++ b/srsue/src/mac/mac.cc @@ -35,7 +35,7 @@ #include #include "srslte/common/log.h" -#include "mac/mac.h" +#include "srsue/hdr/mac/mac.h" #include "srslte/common/pcap.h" diff --git a/srsue/src/mac/mux.cc b/srsue/src/mac/mux.cc index 33d048957..6d1edbebf 100644 --- a/srsue/src/mac/mux.cc +++ b/srsue/src/mac/mux.cc @@ -29,8 +29,8 @@ #define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) #define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) -#include "mac/mux.h" -#include "mac/mac.h" +#include "srsue/hdr/mac/mux.h" +#include "srsue/hdr/mac/mac.h" #include #include diff --git a/srsue/src/mac/proc_bsr.cc b/srsue/src/mac/proc_bsr.cc index f68b6eee8..19b214a74 100644 --- a/srsue/src/mac/proc_bsr.cc +++ b/srsue/src/mac/proc_bsr.cc @@ -29,9 +29,9 @@ #define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) #define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) -#include "mac/proc_bsr.h" -#include "mac/mac.h" -#include "mac/mux.h" +#include "srsue/hdr/mac/proc_bsr.h" +#include "srsue/hdr/mac/mac.h" +#include "srsue/hdr/mac/mux.h" namespace srsue { diff --git a/srsue/src/mac/proc_phr.cc b/srsue/src/mac/proc_phr.cc index 3eb7c82f5..69a5c0de3 100644 --- a/srsue/src/mac/proc_phr.cc +++ b/srsue/src/mac/proc_phr.cc @@ -29,9 +29,9 @@ #define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) #define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) -#include "mac/proc_phr.h" -#include "mac/mac.h" -#include "mac/mux.h" +#include "srsue/hdr/mac/proc_phr.h" +#include "srsue/hdr/mac/mac.h" +#include "srsue/hdr/mac/mux.h" #include "srslte/interfaces/ue_interfaces.h" diff --git a/srsue/src/mac/proc_ra.cc b/srsue/src/mac/proc_ra.cc index 3860fd809..d5efbea4f 100644 --- a/srsue/src/mac/proc_ra.cc +++ b/srsue/src/mac/proc_ra.cc @@ -33,9 +33,9 @@ #include #include -#include "mac/proc_ra.h" -#include "mac/mac.h" -#include "mac/mux.h" +#include "srsue/hdr/mac/proc_ra.h" +#include "srsue/hdr/mac/mac.h" +#include "srsue/hdr/mac/mux.h" /* Random access procedure as specified in Section 5.1 of 36.321 */ diff --git a/srsue/src/mac/proc_sr.cc b/srsue/src/mac/proc_sr.cc index cb31a1c6d..57cd8bdd5 100644 --- a/srsue/src/mac/proc_sr.cc +++ b/srsue/src/mac/proc_sr.cc @@ -29,7 +29,7 @@ #define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) #define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) -#include "mac/proc_sr.h" +#include "srsue/hdr/mac/proc_sr.h" namespace srsue { diff --git a/srsue/src/main.cc b/srsue/src/main.cc index 30a3e3b00..a30892cc7 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -36,10 +36,10 @@ #include #include -#include "ue.h" +#include "srsue/hdr/ue.h" #include "srslte/srslte.h" -#include "metrics_stdout.h" -#include "metrics_csv.h" +#include "srsue/hdr/metrics_stdout.h" +#include "srsue/hdr/metrics_csv.h" #include "srslte/common/metrics_hub.h" #include "srslte/version.h" diff --git a/srsue/src/metrics_csv.cc b/srsue/src/metrics_csv.cc index 54702dc26..360c678f5 100644 --- a/srsue/src/metrics_csv.cc +++ b/srsue/src/metrics_csv.cc @@ -25,7 +25,7 @@ * */ -#include "metrics_csv.h" +#include "srsue/hdr/metrics_csv.h" #include #include diff --git a/srsue/src/metrics_stdout.cc b/srsue/src/metrics_stdout.cc index c8f373284..5d33f967d 100644 --- a/srsue/src/metrics_stdout.cc +++ b/srsue/src/metrics_stdout.cc @@ -25,7 +25,7 @@ * */ -#include "metrics_stdout.h" +#include "srsue/hdr/metrics_stdout.h" #include #include diff --git a/srsue/src/phy/phch_common.cc b/srsue/src/phy/phch_common.cc index 3c3cf1641..13cca2ec8 100644 --- a/srsue/src/phy/phch_common.cc +++ b/srsue/src/phy/phch_common.cc @@ -27,7 +27,7 @@ #include #include #include "srslte/srslte.h" -#include "phy/phch_common.h" +#include "srsue/hdr/phy/phch_common.h" #define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index 49b0af307..01e63cecd 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -28,8 +28,8 @@ #include #include "srslte/srslte.h" #include "srslte/common/log.h" -#include "phy/phch_worker.h" -#include "phy/phch_recv.h" +#include "srsue/hdr/phy/phch_worker.h" +#include "srsue/hdr/phy/phch_recv.h" #define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index 47fdb9591..7ac2ed040 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -26,7 +26,7 @@ #include #include -#include "phy/phch_worker.h" +#include "srsue/hdr/phy/phch_worker.h" #include "srslte/srslte.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/asn1/liblte_rrc.h" diff --git a/srsue/src/phy/phy.cc b/srsue/src/phy/phy.cc index 27b389a4e..90dbc2833 100644 --- a/srsue/src/phy/phy.cc +++ b/srsue/src/phy/phy.cc @@ -36,7 +36,7 @@ #include "srslte/common/threads.h" #include "srslte/common/log.h" -#include "phy/phy.h" +#include "srsue/hdr/phy/phy.h" #define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) diff --git a/srsue/src/phy/prach.cc b/srsue/src/phy/prach.cc index a1bf96c85..5025e6b5d 100644 --- a/srsue/src/phy/prach.cc +++ b/srsue/src/phy/prach.cc @@ -30,8 +30,8 @@ #include "srslte/srslte.h" #include "srslte/common/log.h" -#include "phy/prach.h" -#include "phy/phy.h" +#include "srsue/hdr/phy/prach.h" +#include "srsue/hdr/phy/phy.h" #include "srslte/interfaces/ue_interfaces.h" #define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) diff --git a/srsue/src/ue.cc b/srsue/src/ue.cc index ca8c9002b..fe59bee91 100644 --- a/srsue/src/ue.cc +++ b/srsue/src/ue.cc @@ -25,7 +25,7 @@ */ -#include "ue.h" +#include "srsue/hdr/ue.h" #include "srslte/srslte.h" #include #include diff --git a/srsue/src/ue_base.cc b/srsue/src/ue_base.cc index 71430fc9f..c4b4a2a52 100644 --- a/srsue/src/ue_base.cc +++ b/srsue/src/ue_base.cc @@ -24,8 +24,8 @@ * */ -#include "ue_base.h" -#include "ue.h" +#include "srsue/hdr/ue_base.h" +#include "srsue/hdr/ue.h" #include "srslte/srslte.h" #include "srslte/build_info.h" #include diff --git a/srsue/src/upper/gw.cc b/srsue/src/upper/gw.cc index fbf4bca9f..34db4a226 100644 --- a/srsue/src/upper/gw.cc +++ b/srsue/src/upper/gw.cc @@ -25,7 +25,7 @@ */ -#include "../../hdr/upper/gw.h" +#include "srsue/hdr/upper/gw.h" #include #include diff --git a/srsue/src/upper/nas.cc b/srsue/src/upper/nas.cc index 5b7f40920..882f1d977 100644 --- a/srsue/src/upper/nas.cc +++ b/srsue/src/upper/nas.cc @@ -31,7 +31,7 @@ #include #include #include "srslte/asn1/liblte_rrc.h" -#include "upper/nas.h" +#include "srsue/hdr/upper/nas.h" #include "srslte/common/security.h" #include "srslte/common/bcd_helpers.h" diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index 53e85fac8..05286e05c 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -32,7 +32,7 @@ #include #include // for printing uint64_t #include -#include "upper/rrc.h" +#include "srsue/hdr/upper/rrc.h" #include "srslte/asn1/liblte_rrc.h" #include "srslte/common/security.h" #include "srslte/common/bcd_helpers.h" diff --git a/srsue/src/upper/usim.cc b/srsue/src/upper/usim.cc index d344734ba..ca9075edb 100644 --- a/srsue/src/upper/usim.cc +++ b/srsue/src/upper/usim.cc @@ -26,7 +26,7 @@ #include -#include "upper/usim.h" +#include "srsue/hdr/upper/usim.h" #include "srslte/common/bcd_helpers.h" using namespace srslte; diff --git a/srsue/test/mac/mac_test.cc b/srsue/test/mac/mac_test.cc index 3d21720d4..820c4617e 100644 --- a/srsue/test/mac/mac_test.cc +++ b/srsue/test/mac/mac_test.cc @@ -30,10 +30,10 @@ #include "srslte/asn1/liblte_rrc.h" #include "srslte/radio/radio_multi.h" -#include "phy/phy.h" +#include "srsue/hdr/phy/phy.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/log_filter.h" -#include "mac/mac.h" +#include "srsue/hdr/mac/mac.h" #include "srslte/common/mac_pcap.h" diff --git a/srsue/test/metrics_test.cc b/srsue/test/metrics_test.cc index 52a5f98f9..4a23a55cf 100644 --- a/srsue/test/metrics_test.cc +++ b/srsue/test/metrics_test.cc @@ -29,10 +29,10 @@ #include #include #include -#include "ue_metrics_interface.h" +#include "srsue/hdr/ue_metrics_interface.h" #include "srslte/common/metrics_hub.h" -#include "metrics_stdout.h" -#include "metrics_csv.h" +#include "srsue/hdr/metrics_stdout.h" +#include "srsue/hdr/metrics_csv.h" using namespace srsue; diff --git a/srsue/test/phy/ue_itf_test_prach.cc b/srsue/test/phy/ue_itf_test_prach.cc index 810278c7c..e161139f9 100644 --- a/srsue/test/phy/ue_itf_test_prach.cc +++ b/srsue/test/phy/ue_itf_test_prach.cc @@ -27,7 +27,7 @@ #include #include "srslte/phy/utils/debug.h" -#include "phy/phy.h" +#include "srsue/hdr/phy/phy.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/log_filter.h" #include "srslte/radio/radio_multi.h" diff --git a/srsue/test/phy/ue_itf_test_sib1.cc b/srsue/test/phy/ue_itf_test_sib1.cc index 23f8566be..f302fd7aa 100644 --- a/srsue/test/phy/ue_itf_test_sib1.cc +++ b/srsue/test/phy/ue_itf_test_sib1.cc @@ -27,7 +27,7 @@ #include #include "srslte/phy/utils/debug.h" -#include "phy/phy.h" +#include "srsue/hdr/phy/phy.h" #include "srslte/common/log_filter.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/radio/radio_multi.h" diff --git a/srsue/test/upper/ip_test.cc b/srsue/test/upper/ip_test.cc index afed88ebc..a4f9743cc 100644 --- a/srsue/test/upper/ip_test.cc +++ b/srsue/test/upper/ip_test.cc @@ -16,15 +16,15 @@ #include #include "srslte/phy/utils/debug.h" -#include "mac/mac.h" -#include "phy/phy.h" +#include "srsue/hdr/mac/mac.h" +#include "srsue/hdr/phy/phy.h" #include "srslte/common/threads.h" #include "srslte/common/common.h" #include "srslte/common/buffer_pool.h" #include "srslte/common/logger_file.h" #include "srslte/common/log_filter.h" #include "srslte/upper/rlc.h" -#include "upper/rrc.h" +#include "srsue/hdr/upper/rrc.h" #include "srslte/radio/radio_multi.h" #define START_TUNTAP diff --git a/srsue/test/upper/nas_test.cc b/srsue/test/upper/nas_test.cc index 2fb3efe95..51fc9f83b 100644 --- a/srsue/test/upper/nas_test.cc +++ b/srsue/test/upper/nas_test.cc @@ -26,11 +26,11 @@ #include #include -#include "upper/usim.h" -#include "upper/nas.h" +#include "srsue/hdr/upper/usim.h" +#include "srsue/hdr/upper/nas.h" #include "srslte/upper/rlc.h" -#include "upper/rrc.h" -#include "mac/mac.h" +#include "srsue/hdr/upper/rrc.h" +#include "srsue/hdr/mac/mac.h" #include "srslte/common/log_filter.h" #include "srslte/upper/pdcp_entity.h" #include "srslte/upper/pdcp.h" diff --git a/srsue/test/upper/usim_test.cc b/srsue/test/upper/usim_test.cc index bf60e124c..225bee36d 100644 --- a/srsue/test/upper/usim_test.cc +++ b/srsue/test/upper/usim_test.cc @@ -25,7 +25,7 @@ */ #include -#include "upper/usim.h" +#include "srsue/hdr/upper/usim.h" #include "srslte/common/log_filter.h" #include From 2dcd6695bce523e74b31dbcd13731cad89423975 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 3 Apr 2018 10:48:52 +0200 Subject: [PATCH 135/143] remove obsolete config.h --- lib/include/srslte/common/config.h | 57 ------------------------------ 1 file changed, 57 deletions(-) delete mode 100644 lib/include/srslte/common/config.h diff --git a/lib/include/srslte/common/config.h b/lib/include/srslte/common/config.h deleted file mode 100644 index 3231355fa..000000000 --- a/lib/include/srslte/common/config.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - * - * \section COPYRIGHT - * - * Copyright 2013-2015 Software Radio Systems Limited - * - * \section LICENSE - * - * This file is part of the srsUE library. - * - * srsUE is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * srsUE is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * A copy of the GNU Affero General Public License can be found in - * the LICENSE file in the top-level directory of this distribution - * and at http://www.gnu.org/licenses/. - * - */ - -#ifndef CONFIG_H -#define CONFIG_H - -// Generic helper definitions for shared library support -#if defined _WIN32 || defined __CYGWIN__ - #define SRSAPPS_IMPORT __declspec(dllimport) - #define SRSAPPS_EXPORT __declspec(dllexport) - #define SRSAPPS_LOCAL -#else - #if __GNUC__ >= 4 - #define SRSAPPS_IMPORT __attribute__ ((visibility ("default"))) - #define SRSAPPS_EXPORT __attribute__ ((visibility ("default"))) - #else - #define SRSAPPS_IMPORT - #define SRSAPPS_EXPORT - #define SRSAPPS_LOCAL - #endif -#endif - -// Define SRSAPPS_API -// is used for the public API symbols. -#ifdef SRSAPPS_DLL_EXPORTS // defined if we are building the SRSAPPS DLL (instead of using it) - #define SRSAPPS_EXPORT -#else - #define SRSAPPS_IMPORT -#endif - -// cf_t definition -typedef _Complex float cf_t; - -#endif // CONFIG_H From 4e05266ea8cf8b6d1d05376b3a9162471a978474 Mon Sep 17 00:00:00 2001 From: Joseph Giovatto Date: Mon, 2 Apr 2018 12:25:31 -0400 Subject: [PATCH 136/143] added printf format check for hex logs --- lib/include/srslte/common/log.h | 12 ++++++++---- lib/include/srslte/common/log_filter.h | 8 ++++---- lib/src/common/log_filter.cc | 16 ++++++++-------- srsenb/src/phy/phch_worker.cc | 4 ++-- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/include/srslte/common/log.h b/lib/include/srslte/common/log.h index 45c359629..5ef3107f9 100644 --- a/lib/include/srslte/common/log.h +++ b/lib/include/srslte/common/log.h @@ -129,10 +129,14 @@ public: virtual void debug(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; // Same with hex dump - virtual void error_hex(uint8_t *hex, int size, std::string message, ...){error("error_hex not implemented.\n");} - virtual void warning_hex(uint8_t *hex, int size, std::string message, ...){error("warning_hex not implemented.\n");} - virtual void info_hex(uint8_t *hex, int size, std::string message, ...){error("info_hex not implemented.\n");} - virtual void debug_hex(uint8_t *hex, int size, std::string message, ...){error("debug_hex not implemented.\n");} + virtual void error_hex(uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + {error("error_hex not implemented.\n");} + virtual void warning_hex(uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + {error("warning_hex not implemented.\n");} + virtual void info_hex(uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + {error("info_hex not implemented.\n");} + virtual void debug_hex(uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + {error("debug_hex not implemented.\n");} protected: std::string get_service_name() { return service_name; } diff --git a/lib/include/srslte/common/log_filter.h b/lib/include/srslte/common/log_filter.h index 430a59199..ac01d7cd4 100644 --- a/lib/include/srslte/common/log_filter.h +++ b/lib/include/srslte/common/log_filter.h @@ -63,10 +63,10 @@ public: void info(const char * message, ...); void debug(const char * message, ...); - void error_hex(uint8_t *hex, int size, std::string message, ...); - void warning_hex(uint8_t *hex, int size, std::string message, ...); - void info_hex(uint8_t *hex, int size, std::string message, ...); - void debug_hex(uint8_t *hex, int size, std::string message, ...); + void error_hex(uint8_t *hex, int size, const char * message, ...); + void warning_hex(uint8_t *hex, int size, const char * message, ...); + void info_hex(uint8_t *hex, int size, const char * message, ...); + void debug_hex(uint8_t *hex, int size, const char * message, ...); class time_itf { public: diff --git a/lib/src/common/log_filter.cc b/lib/src/common/log_filter.cc index b79e222e7..ff9809a6b 100644 --- a/lib/src/common/log_filter.cc +++ b/lib/src/common/log_filter.cc @@ -190,45 +190,45 @@ void log_filter::debug(const char * message, ...) { } } -void log_filter::error_hex(uint8_t *hex, int size, std::string message, ...) { +void log_filter::error_hex(uint8_t *hex, int size, const char * message, ...) { if (level >= LOG_LEVEL_ERROR) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_ERROR, tti, args_msg, hex, size); va_end(args); free(args_msg); } } -void log_filter::warning_hex(uint8_t *hex, int size, std::string message, ...) { +void log_filter::warning_hex(uint8_t *hex, int size, const char * message, ...) { if (level >= LOG_LEVEL_WARNING) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_WARNING, tti, args_msg, hex, size); va_end(args); free(args_msg); } } -void log_filter::info_hex(uint8_t *hex, int size, std::string message, ...) { +void log_filter::info_hex(uint8_t *hex, int size, const char * message, ...) { if (level >= LOG_LEVEL_INFO) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_INFO, tti, args_msg, hex, size); va_end(args); free(args_msg); } } -void log_filter::debug_hex(uint8_t *hex, int size, std::string message, ...) { +void log_filter::debug_hex(uint8_t *hex, int size, const char * message, ...) { if (level >= LOG_LEVEL_DEBUG) { char *args_msg; va_list args; va_start(args, message); - if(vasprintf(&args_msg, message.c_str(), args) > 0) + if(vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_DEBUG, tti, args_msg, hex, size); va_end(args); free(args_msg); diff --git a/srsenb/src/phy/phch_worker.cc b/srsenb/src/phy/phch_worker.cc index 5524be442..db7a13b32 100644 --- a/srsenb/src/phy/phch_worker.cc +++ b/srsenb/src/phy/phch_worker.cc @@ -602,8 +602,8 @@ int phch_worker::decode_pusch(srslte_enb_ul_pusch_t *grants, uint32_t nof_pusch) } */ log_h->info_hex(grants[i].data, phy_grant.mcs.tbs / 8, - "PUSCH: rnti=0x%x, prb=(%d,%d), tbs=%d, mcs=%d, rv=%d, snr=%.1f dB, n_iter=%d, crc=%s%s%s%s%s%s%s\n", - rnti, phy_grant.n_prb[0], phy_grant.n_prb[0] + phy_grant.L_prb, + "PUSCH: rnti=0x%x, prb=(%d,%d), tbs=%d, mcs=%d, idx=%d, rv=%d, snr=%.1f dB, n_iter=%d, crc=%s%s%s%s%s%s%s%s\n", + rnti, phy_grant.n_prb[0], phy_grant.n_prb[0], phy_grant.L_prb, phy_grant.mcs.tbs / 8, phy_grant.mcs.idx, grants[i].grant.rv_idx, snr_db, srslte_pusch_last_noi(&enb_ul.pusch), From 802f8b716f910993dd07f0e5b4cb901107179382 Mon Sep 17 00:00:00 2001 From: Joseph Giovatto Date: Mon, 2 Apr 2018 16:05:14 -0400 Subject: [PATCH 137/143] set msg and hex buf to const * --- lib/include/srslte/common/log_filter.h | 14 +++++++------- lib/src/common/log_filter.cc | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/include/srslte/common/log_filter.h b/lib/include/srslte/common/log_filter.h index ac01d7cd4..9addc9ec2 100644 --- a/lib/include/srslte/common/log_filter.h +++ b/lib/include/srslte/common/log_filter.h @@ -63,10 +63,10 @@ public: void info(const char * message, ...); void debug(const char * message, ...); - void error_hex(uint8_t *hex, int size, const char * message, ...); - void warning_hex(uint8_t *hex, int size, const char * message, ...); - void info_hex(uint8_t *hex, int size, const char * message, ...); - void debug_hex(uint8_t *hex, int size, const char * message, ...); + void error_hex(const uint8_t *hex, int size, const char * message, ...); + void warning_hex(const uint8_t *hex, int size, const char * message, ...); + void info_hex(const uint8_t *hex, int size, const char * message, ...); + void debug_hex(const uint8_t *hex, int size, const char * message, ...); class time_itf { public: @@ -89,11 +89,11 @@ private: logger_stdout def_logger_stdout; - void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg); - void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg, uint8_t *hex, int size); + void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, const char *msg); + void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, const char *msg, const uint8_t *hex, int size); void all_log_line(srslte::LOG_LEVEL_ENUM level, uint32_t tti, std::string file, int line, char *msg); std::string now_time(); - std::string hex_string(uint8_t *hex, int size); + std::string hex_string(const uint8_t *hex, int size); }; } // namespace srsue diff --git a/lib/src/common/log_filter.cc b/lib/src/common/log_filter.cc index ff9809a6b..a86a36f1e 100644 --- a/lib/src/common/log_filter.cc +++ b/lib/src/common/log_filter.cc @@ -68,7 +68,7 @@ void log_filter::init(std::string layer, logger *logger_, bool tti) void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, - char *msg) + const char *msg) { if(logger_h) { std::stringstream ss; @@ -97,8 +97,8 @@ void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, - char *msg, - uint8_t *hex, + const char *msg, + const uint8_t *hex, int size) { if(logger_h) { @@ -190,7 +190,7 @@ void log_filter::debug(const char * message, ...) { } } -void log_filter::error_hex(uint8_t *hex, int size, const char * message, ...) { +void log_filter::error_hex(const uint8_t *hex, int size, const char * message, ...) { if (level >= LOG_LEVEL_ERROR) { char *args_msg; va_list args; @@ -201,7 +201,7 @@ void log_filter::error_hex(uint8_t *hex, int size, const char * message, ...) { free(args_msg); } } -void log_filter::warning_hex(uint8_t *hex, int size, const char * message, ...) { +void log_filter::warning_hex(const uint8_t *hex, int size, const char * message, ...) { if (level >= LOG_LEVEL_WARNING) { char *args_msg; va_list args; @@ -212,7 +212,7 @@ void log_filter::warning_hex(uint8_t *hex, int size, const char * message, ...) free(args_msg); } } -void log_filter::info_hex(uint8_t *hex, int size, const char * message, ...) { +void log_filter::info_hex(const uint8_t *hex, int size, const char * message, ...) { if (level >= LOG_LEVEL_INFO) { char *args_msg; va_list args; @@ -223,7 +223,7 @@ void log_filter::info_hex(uint8_t *hex, int size, const char * message, ...) { free(args_msg); } } -void log_filter::debug_hex(uint8_t *hex, int size, const char * message, ...) { +void log_filter::debug_hex(const uint8_t *hex, int size, const char * message, ...) { if (level >= LOG_LEVEL_DEBUG) { char *args_msg; va_list args; @@ -277,7 +277,7 @@ std::string log_filter::now_time() return std::string(buffer); } -std::string log_filter::hex_string(uint8_t *hex, int size) +std::string log_filter::hex_string(const uint8_t *hex, int size) { std::stringstream ss; int c = 0; From b298d3d3f95306b41d9c1b13b01f665876edf74a Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 3 Apr 2018 12:16:22 +0200 Subject: [PATCH 138/143] add missing const keyword to log_filter's members --- lib/include/srslte/common/log.h | 8 ++++---- lib/include/srslte/common/log_filter.h | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/include/srslte/common/log.h b/lib/include/srslte/common/log.h index 7d8f0a8cd..b47f79d90 100644 --- a/lib/include/srslte/common/log.h +++ b/lib/include/srslte/common/log.h @@ -129,13 +129,13 @@ public: virtual void debug(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; // Same with hex dump - virtual void error_hex(uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + virtual void error_hex(const uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) {error("error_hex not implemented.\n");} - virtual void warning_hex(uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + virtual void warning_hex(const uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) {error("warning_hex not implemented.\n");} - virtual void info_hex(uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + virtual void info_hex(const uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) {error("info_hex not implemented.\n");} - virtual void debug_hex(uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) + virtual void debug_hex(const uint8_t *hex, int size, const char *, ...) __attribute__((format (printf, 4, 5))) {error("debug_hex not implemented.\n");} protected: diff --git a/lib/include/srslte/common/log_filter.h b/lib/include/srslte/common/log_filter.h index ea739082a..1296fbbbd 100644 --- a/lib/include/srslte/common/log_filter.h +++ b/lib/include/srslte/common/log_filter.h @@ -57,16 +57,16 @@ public: void init(std::string layer, logger *logger_, bool tti=false); - void console(const char * message, ...); - void error(const char * message, ...); - void warning(const char * message, ...); - void info(const char * message, ...); - void debug(const char * message, ...); - - void error_hex(const uint8_t *hex, int size, const char * message, ...); - void warning_hex(const uint8_t *hex, int size, const char * message, ...); - void info_hex(const uint8_t *hex, int size, const char * message, ...); - void debug_hex(const uint8_t *hex, int size, const char * message, ...); + void console(const char * message, ...) __attribute__ ((format (printf, 2, 3))); + void error(const char * message, ...) __attribute__ ((format (printf, 2, 3))); + void warning(const char * message, ...) __attribute__ ((format (printf, 2, 3))); + void info(const char * message, ...) __attribute__ ((format (printf, 2, 3))); + void debug(const char * message, ...) __attribute__ ((format (printf, 2, 3))); + + void error_hex(const uint8_t *hex, int size, const char * message, ...) __attribute__((format (printf, 4, 5))); + void warning_hex(const uint8_t *hex, int size, const char * message, ...) __attribute__((format (printf, 4, 5))); + void info_hex(const uint8_t *hex, int size, const char * message, ...) __attribute__((format (printf, 4, 5))); + void debug_hex(const uint8_t *hex, int size, const char * message, ...) __attribute__((format (printf, 4, 5))); class time_itf { public: From 319f47336392ec1ccd496274f749de33430453f5 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Wed, 4 Apr 2018 12:15:10 +0200 Subject: [PATCH 139/143] fix remaining printf warnings --- srsenb/src/enb.cc | 2 +- srsepc/src/hss/hss.cc | 3 ++- srsepc/src/mme/mme_gtpc.cc | 13 +++++++------ srsepc/src/mme/s1ap.cc | 7 ++++--- srsepc/src/spgw/spgw.cc | 7 ++++--- srsue/src/ue_base.cc | 2 +- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/srsenb/src/enb.cc b/srsenb/src/enb.cc index 85cda6185..e91aea7bf 100644 --- a/srsenb/src/enb.cc +++ b/srsenb/src/enb.cc @@ -296,7 +296,7 @@ void enb::handle_rf_msg(srslte_rf_error_t error) str.erase(std::remove(str.begin(), str.end(), '\n'), str.end()); str.erase(std::remove(str.begin(), str.end(), '\r'), str.end()); str.push_back('\n'); - rf_log.info(str.c_str()); + rf_log.info("%s\n", str.c_str()); } } diff --git a/srsepc/src/hss/hss.cc b/srsepc/src/hss/hss.cc index d9a55960b..9a8db0e3a 100644 --- a/srsepc/src/hss/hss.cc +++ b/srsepc/src/hss/hss.cc @@ -28,6 +28,7 @@ #include #include #include +#include // for printing uint64_t #include "srsepc/hdr/hss/hss.h" #include "srslte/common/security.h" @@ -564,7 +565,7 @@ hss::increment_sqn(uint64_t imsi) sqn++; - m_hss_log->debug("Incremented SQN (IMSI: %015lu) SQN: %d\n", imsi, sqn); + m_hss_log->debug("Incremented SQN (IMSI: %" PRIu64 ") SQN: %" PRIu64 "\n", imsi, sqn); for(int i = 0; i < 6; i++){ ue_ctx->sqn[i] = p[5-i]; diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 1f53338c0..7c30bfa3b 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -25,6 +25,7 @@ */ #include +#include // for printing uint64_t #include "srslte/asn1/gtpc.h" #include "srsepc/hdr/mme/mme_gtpc.h" #include "srsepc/hdr/mme/s1ap.h" @@ -115,10 +116,10 @@ mme_gtpc::send_create_session_request(uint64_t imsi) cs_req->sender_f_teid.teid = get_new_ctrl_teid(); cs_req->sender_f_teid.ipv4 = m_mme_gtpc_ip; - m_mme_gtpc_log->info("Next MME control TEID: %lu \n", m_next_ctrl_teid); - m_mme_gtpc_log->info("Allocated MME control TEID: %lu \n", cs_req->sender_f_teid.teid); - m_mme_gtpc_log->console("Creating Session Response -- IMSI: %015lu \n", imsi); - m_mme_gtpc_log->console("Creating Session Response -- MME control TEID: %lu \n", cs_req->sender_f_teid.teid); + m_mme_gtpc_log->info("Next MME control TEID: %d\n", m_next_ctrl_teid); + m_mme_gtpc_log->info("Allocated MME control TEID: %d\n", cs_req->sender_f_teid.teid); + m_mme_gtpc_log->console("Creating Session Response -- IMSI: %" PRIu64 "\n", imsi); + m_mme_gtpc_log->console("Creating Session Response -- MME control TEID: %d\n", cs_req->sender_f_teid.teid); // APN strncpy(cs_req->apn, m_s1ap->m_s1ap_args.mme_apn.c_str(), sizeof(cs_req->apn)-1); @@ -185,7 +186,7 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu) } uint64_t imsi = id_it->second; - m_mme_gtpc_log->info("MME GTPC Ctrl TEID %d, IMSI %d\n", cs_resp_pdu->header.teid, imsi); + m_mme_gtpc_log->info("MME GTPC Ctrl TEID %" PRIu64 ", IMSI %" PRIu64 "\n", cs_resp_pdu->header.teid, imsi); //Get S-GW Control F-TEID srslte::gtp_fteid_t sgw_ctr_fteid; @@ -309,7 +310,7 @@ mme_gtpc::handle_modify_bearer_response(srslte::gtpc_pdu *mb_resp_pdu) void mme_gtpc::send_delete_session_request(uint64_t imsi) { - m_mme_gtpc_log->info("Sending GTP-C Delete Session Request request. IMSI %d\n",imsi); + m_mme_gtpc_log->info("Sending GTP-C Delete Session Request request. IMSI %" PRIu64 "\n",imsi); srslte::gtpc_pdu del_req_pdu; srslte::gtp_fteid_t sgw_ctr_fteid; srslte::gtp_fteid_t mme_ctr_fteid; diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 639725ee5..ccd2536c1 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -26,6 +26,7 @@ #include #include +#include // for printing uint64_t #include "srslte/common/bcd_helpers.h" #include "srsepc/hdr/mme/s1ap.h" #include "srslte/asn1/gtpc.h" @@ -486,7 +487,7 @@ s1ap::delete_ue_ctx(uint64_t imsi) ue_ctx_t *ue_ctx = find_ue_ctx_from_imsi(imsi); if(ue_ctx == NULL) { - m_s1ap_log->info("Cannot delete UE context, UE not found. IMSI: %d\n", imsi); + m_s1ap_log->info("Cannot delete UE context, UE not found. IMSI: %" PRIu64 "\n", imsi); return false; } @@ -528,8 +529,8 @@ s1ap::activate_eps_bearer(uint64_t imsi, uint8_t ebi) ue_ecm_ctx_t * ecm_ctx = &ue_ctx_it->second->ecm_ctx; if (ecm_ctx->erabs_ctx[ebi].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,ecm_ctx->erabs_ctx[ebi].state); - m_s1ap_log->console("Could not be activate EPS Bearer, bearer in wrong state: MME S1AP Id %d, EPS Bearer id %d\n",mme_ue_s1ap_id,ebi,ecm_ctx->erabs_ctx[ebi].state); + 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, ecm_ctx->erabs_ctx[ebi].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, ecm_ctx->erabs_ctx[ebi].state); return; } diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index eec7bb4ec..cbd3e524b 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -33,6 +33,7 @@ #include #include #include +#include // for printing uint64_t #include "srsepc/hdr/spgw/spgw.h" #include "srsepc/hdr/mme/mme_gtpc.h" #include "srslte/upper/gtpu.h" @@ -401,7 +402,7 @@ spgw::handle_s1u_pdu(srslte::byte_buffer_t *msg) int n = write(m_sgi_if, msg->msg, msg->N_bytes); if(n<0) { - m_spgw_log->error("Could not write to TUN interface.\n",n); + m_spgw_log->error("Could not write to TUN interface.\n"); } else { @@ -444,8 +445,8 @@ spgw::create_gtp_ctx(struct srslte::gtpc_create_session_request *cs_req) //in_addr_t ue_ip = inet_addr("172.16.0.2"); uint8_t default_bearer_id = 5; - m_spgw_log->console("SPGW: Allocated Ctrl TEID %d\n", spgw_uplink_ctrl_teid); - m_spgw_log->console("SPGW: Allocated User TEID %d\n", spgw_uplink_user_teid); + m_spgw_log->console("SPGW: Allocated Ctrl TEID %" PRIu64 "\n", spgw_uplink_ctrl_teid); + m_spgw_log->console("SPGW: Allocated User TEID %" PRIu64 "\n", spgw_uplink_user_teid); struct in_addr ue_ip_; ue_ip_.s_addr=ue_ip; m_spgw_log->console("SPGW: Allocate UE IP %s\n", inet_ntoa(ue_ip_)); diff --git a/srsue/src/ue_base.cc b/srsue/src/ue_base.cc index c4b4a2a52..b3fc56132 100644 --- a/srsue/src/ue_base.cc +++ b/srsue/src/ue_base.cc @@ -104,7 +104,7 @@ void ue_base::handle_rf_msg(srslte_rf_error_t error) str.erase(std::remove(str.begin(), str.end(), '\n'), str.end()); str.erase(std::remove(str.begin(), str.end(), '\r'), str.end()); str.push_back('\n'); - rf_log.info(str.c_str()); + rf_log.info("%s\n", str.c_str()); } } From e7a268d79bf2e94f9b961ebff3624be5adae2a10 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Wed, 4 Apr 2018 12:20:32 +0200 Subject: [PATCH 140/143] fix SIMD compile issue on NEON --- lib/include/srslte/phy/utils/simd.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/include/srslte/phy/utils/simd.h b/lib/include/srslte/phy/utils/simd.h index 66295f2ce..f6d7a0a44 100644 --- a/lib/include/srslte/phy/utils/simd.h +++ b/lib/include/srslte/phy/utils/simd.h @@ -706,7 +706,11 @@ static inline void srslte_simd_cf_storeu(float *re, float *im, simd_cf_t simdreg } static inline simd_f_t srslte_simd_cf_re(simd_cf_t in) { +#ifdef HAVE_NEON + simd_f_t out = in.val[0]; +#else simd_f_t out = in.re; +#endif /*HAVE_NEON*/ #ifndef LV_HAVE_AVX512 #ifdef LV_HAVE_AVX2 /* Permute for AVX registers (mis SSE registers) */ From 8a831379c161f3970ae8203aac17260eda0cfdec Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Wed, 4 Apr 2018 15:52:36 +0200 Subject: [PATCH 141/143] fix RLC AM SDU reset --- lib/src/upper/rlc_am.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 2537ee48c..407d912ea 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -127,10 +127,10 @@ void rlc_am::reset() pthread_mutex_lock(&mutex); reordering_timeout.reset(); if(tx_sdu) { - pool->deallocate(tx_sdu); + tx_sdu->reset(); } if(rx_sdu) { - pool->deallocate(rx_sdu); + rx_sdu->reset(); } vt_a = 0; From d42316fb68bc3ef4a31bd1d404b4dd5c46e66d35 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Wed, 4 Apr 2018 17:31:33 +0200 Subject: [PATCH 142/143] fix RLC AM reset again to dealloc SDUs --- lib/src/upper/rlc_am.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 407d912ea..895fd74b8 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -127,10 +127,12 @@ void rlc_am::reset() pthread_mutex_lock(&mutex); reordering_timeout.reset(); if(tx_sdu) { - tx_sdu->reset(); + pool->deallocate(tx_sdu); + tx_sdu = NULL; } if(rx_sdu) { - rx_sdu->reset(); + pool->deallocate(rx_sdu); + rx_sdu = NULL; } vt_a = 0; From 9a7357cc945ecb7165a2178f91d34b883fef0937 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Mon, 9 Apr 2018 17:19:21 +0200 Subject: [PATCH 143/143] bump version to 18.03.1 --- CHANGELOG | 4 ++++ cmake/modules/SRSLTEVersion.cmake | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 9bed0247c..7a3a03e8a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,10 @@ Change Log for Releases ============================== +## 18.03.1 + * Fixed compilation for NEON + * Fixed logging and RLC AM issue + ## 18.03 * Many bug-fixes and improved stability and performance in all parts diff --git a/cmake/modules/SRSLTEVersion.cmake b/cmake/modules/SRSLTEVersion.cmake index 30d2707b0..11b2e79e9 100644 --- a/cmake/modules/SRSLTEVersion.cmake +++ b/cmake/modules/SRSLTEVersion.cmake @@ -20,5 +20,5 @@ SET(SRSLTE_VERSION_MAJOR 18) SET(SRSLTE_VERSION_MINOR 3) -SET(SRSLTE_VERSION_PATCH 0) +SET(SRSLTE_VERSION_PATCH 1) SET(SRSLTE_VERSION_STRING "${SRSLTE_VERSION_MAJOR}.${SRSLTE_VERSION_MINOR}.${SRSLTE_VERSION_PATCH}")