From de8679b53657c5f4c143d72cddcbf75a3a560e27 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 23 Jul 2018 15:30:19 +0100 Subject: [PATCH] Continuing to cleanup. Starting to compile again. --- .../srslte/interfaces/epc_interfaces.h | 11 +++- srsepc/hdr/mme/mme_gtpc.h | 2 +- srsepc/hdr/mme/nas.h | 9 +++ srsepc/src/mme/mme_gtpc.cc | 20 +++--- srsepc/src/mme/nas.cc | 64 ++++++++----------- srsepc/src/mme/s1ap_ctx_mngmt_proc.cc | 2 +- 6 files changed, 54 insertions(+), 54 deletions(-) diff --git a/lib/include/srslte/interfaces/epc_interfaces.h b/lib/include/srslte/interfaces/epc_interfaces.h index d20366da1..7af9b9159 100644 --- a/lib/include/srslte/interfaces/epc_interfaces.h +++ b/lib/include/srslte/interfaces/epc_interfaces.h @@ -20,14 +20,18 @@ */ #ifndef SRSLTE_EPC_INTERFACES_H #define SRSLTE_EPC_INTERFACES_H +#include "srslte/asn1/gtpc_ies.h" namespace srsepc { +class nas; + //NAS -> GTP-C class gtpc_interface_nas { public: virtual bool send_create_session_request(uint64_t imsi) = 0; + virtual bool send_modify_bearer_request(uint64_t imsi, uint16_t erab_to_modify, struct srslte::gtpc_f_teid_ie *enb_fteid) = 0; virtual bool send_delete_session_request(uint64_t imsi) = 0; }; @@ -42,8 +46,11 @@ public: class s1ap_interface_nas { public: - virtual bool send_initial_context_setup_request(uint64_t imsi, uint16_t erab_to_setup) = 0; - virtual bool send_ue_context_release_command(uint32_t mme_ue_s1ap_id) = 0; + virtual uint32_t allocate_m_tmsi(uint64_t imsi) = 0; + virtual uint32_t get_next_mme_ue_s1ap_id() = 0; + virtual bool add_nas_ctx_to_imsi_map(nas *nas_ctx) = 0; + virtual bool send_initial_context_setup_request(uint64_t imsi, uint16_t erab_to_setup) = 0; + virtual bool send_ue_context_release_command(uint32_t mme_ue_s1ap_id) = 0; }; //NAS -> HSS diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index 38905bd1c..9c502a576 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -54,7 +54,7 @@ public: uint32_t get_new_ctrl_teid(); 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, esm_ctx_t *bearer_ctx); + void send_modify_bearer_request(uint64_t imsi, uint16_t erab_to_modify, srslte::gtp_fteid_t *enb_fteid); 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); diff --git a/srsepc/hdr/mme/nas.h b/srsepc/hdr/mme/nas.h index 5b32cfce2..b4d999e39 100644 --- a/srsepc/hdr/mme/nas.h +++ b/srsepc/hdr/mme/nas.h @@ -134,6 +134,8 @@ typedef struct{ class nas { public: + nas(); + /*Initial UE messages*/ bool handle_nas_attach_request( uint32_t enb_ue_s1ap_id, srslte::byte_buffer_t *nas_msg, @@ -213,7 +215,14 @@ private: gtpc_interface_nas *m_gtpc; s1ap_interface_nas *m_s1ap; hss_interface_nas *m_hss; + + uint16_t m_mcc; + uint16_t m_mnc; + uint16_t m_mme_group; + uint16_t m_mme_code; + uint16_t m_tac; std::string m_apn; + std::string m_dns; }; }//namespace diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 3ce8d1f61..573093da3 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -251,11 +251,10 @@ mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu) void -mme_gtpc::send_modify_bearer_request(uint64_t imsi, esm_ctx_t *esm_ctx) +mme_gtpc::send_modify_bearer_request(uint64_t imsi, uint16_t erab_to_modify, srslte::gtp_fteid_t *enb_fteid) { m_mme_gtpc_log->info("Sending GTP-C Modify bearer request\n"); srslte::gtpc_pdu mb_req_pdu; - srslte::gtp_fteid_t *enb_fteid = &esm_ctx->enb_fteid; std::map::iterator it = m_imsi_to_gtpc_ctx.find(imsi); if (it == m_imsi_to_gtpc_ctx.end()) { @@ -270,7 +269,7 @@ mme_gtpc::send_modify_bearer_request(uint64_t imsi, esm_ctx_t *esm_ctx) header->type = srslte::GTPC_MSG_TYPE_MODIFY_BEARER_REQUEST; srslte::gtpc_modify_bearer_request *mb_req = &mb_req_pdu.choice.modify_bearer_request; - mb_req->eps_bearer_context_to_modify.ebi = esm_ctx->erab_id; + mb_req->eps_bearer_context_to_modify.ebi = erab_to_modify; 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; @@ -291,8 +290,7 @@ 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 imsi_it = m_mme_ctr_teid_to_imsi.find(mme_ctrl_teid); - if(imsi_it == m_mme_ctr_teid_to_imsi.end()) - { + if (imsi_it == m_mme_ctr_teid_to_imsi.end()) { m_mme_gtpc_log->error("Could not find IMSI from control TEID\n"); return; } @@ -311,13 +309,14 @@ mme_gtpc::send_delete_session_request(uint64_t imsi) srslte::gtpc_pdu del_req_pdu; 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()) - { + 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; @@ -336,12 +335,9 @@ mme_gtpc::send_delete_session_request(uint64_t imsi) //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()) - { + if (it_imsi == m_mme_ctr_teid_to_imsi.end()) { m_mme_gtpc_log->error("Could not find IMSI from MME ctr TEID"); - } - else - { + } else { m_mme_ctr_teid_to_imsi.erase(it_imsi); } m_imsi_to_gtpc_ctx.erase(it_ctx); diff --git a/srsepc/src/mme/nas.cc b/srsepc/src/mme/nas.cc index 241ce36bb..ce5c003fd 100644 --- a/srsepc/src/mme/nas.cc +++ b/srsepc/src/mme/nas.cc @@ -37,8 +37,6 @@ namespace srsepc{ nas::nas() {} -nas::~nas() {} - /******************************* * * Handle UE Initiating Messages @@ -52,8 +50,6 @@ nas::~nas() {} * Handle Uplink NAS Transport message * */ - -//FIXME re-factor to reduce code duplication for messages that can be both initiating messages and uplink NAS messages bool nas::handle_nas_detach_request(srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_msg, bool *reply_flag) { @@ -109,7 +105,7 @@ nas::handle_nas_authentication_response(srslte::byte_buffer_t *nas_msg, srslte:: m_nas_log->warning("UE Authentication Rejected.\n"); //Send back Athentication Reject - pack_authentication_reject(reply_buffer, m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id); + pack_authentication_reject(reply_buffer); *reply_flag = true; m_nas_log->console("Downlink NAS: Sending Authentication Reject.\n"); return false; @@ -192,7 +188,7 @@ nas::handle_nas_attach_complete(srslte::byte_buffer_t *nas_msg, srslte::byte_buf } if (m_emm_ctx.state == EMM_STATE_DEREGISTERED) { //Attach requested from attach request - m_gtpc->send_modify_bearer_request(m_emm_ctx.imsi, &m_esm_ctx[act_bearer.eps_bearer_id]); + m_gtpc->send_modify_bearer_request(m_emm_ctx.imsi, act_bearer.eps_bearer_id, &m_esm_ctx[act_bearer.eps_bearer_id].enb_fteid); //Send reply to eNB m_nas_log->console("Packing EMM Information\n"); *reply_flag = pack_emm_information(reply_msg); @@ -314,10 +310,6 @@ nas::handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, srslte: //m_nas_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; - //Get decimal MCC and MNC - uint32_t mcc = m_s1ap->get_mcc(); - uint32_t mnc = m_s1ap->get_mnc(); - //T3412 Timer tau_acc.t3412_present = true; tau_acc.t3412.unit = LIBLTE_MME_GPRS_TIMER_UNIT_1_MINUTE; // GPRS 1 minute unit @@ -326,10 +318,10 @@ nas::handle_tracking_area_update_request(srslte::byte_buffer_t *nas_msg, srslte: //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->get_mme_group(); - tau_acc.guti.guti.mme_code = m_s1ap->get_mme_code(); + tau_acc.guti.guti.mcc = m_mcc; + tau_acc.guti.guti.mnc = m_mnc; + tau_acc.guti.guti.mme_group_id = m_mme_group; + tau_acc.guti.guti.mme_code = m_mme_code; tau_acc.guti.guti.m_tmsi = 0xF000; m_nas_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, @@ -467,7 +459,7 @@ nas::pack_authentication_request(srslte::byte_buffer_t *reply_msg) } bool -nas::pack_authentication_reject(srslte::byte_buffer_t *reply_msg, uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id) +nas::pack_authentication_reject(srslte::byte_buffer_t *reply_msg) { srslte::byte_buffer_t *nas_buffer = m_pool->allocate(); @@ -485,8 +477,8 @@ nas::pack_authentication_reject(srslte::byte_buffer_t *reply_msg, uint32_t enb_u //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 = m_ecm_ctx.mme_ue_s1ap_id; + dw_nas->eNB_UE_S1AP_ID.ENB_UE_S1AP_ID = m_ecm_ctx.enb_ue_s1ap_id; dw_nas->HandoverRestrictionList_present=false; dw_nas->SubscriberProfileIDforRFP_present=false; @@ -689,29 +681,26 @@ nas::pack_attach_accept(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; - //Get decimal MCC and MNC - uint32_t mcc = m_s1ap->get_mcc(); - uint32_t mnc = m_s1ap->get_mnc(); - //Attach accept attach_accept.eps_attach_result = m_emm_ctx.attach_type; //FIXME: Set t3412 from config attach_accept.t3412.unit = LIBLTE_MME_GPRS_TIMER_UNIT_1_MINUTE; // GPRS 1 minute unit attach_accept.t3412.value = 30; // 30 minute periodic timer + //FIXME: Set tai_list from config attach_accept.tai_list.N_tais = 1; - attach_accept.tai_list.tai[0].mcc = mcc; - attach_accept.tai_list.tai[0].mnc = mnc; - attach_accept.tai_list.tai[0].tac = m_s1ap->m_s1ap_args.tac; + attach_accept.tai_list.tai[0].mcc = m_mcc; + attach_accept.tai_list.tai[0].mnc = m_mnc; + attach_accept.tai_list.tai[0].tac = m_tac; //Allocate a GUTI ot the UE attach_accept.guti_present=true; attach_accept.guti.type_of_id = 6; //110 -> GUTI - attach_accept.guti.guti.mcc = mcc; - 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.mcc = m_mcc; + attach_accept.guti.guti.mnc = m_mnc; + attach_accept.guti.guti.mme_group_id = m_mme_group; + attach_accept.guti.guti.mme_code = m_mme_code; attach_accept.guti.guti.m_tmsi = m_s1ap->allocate_m_tmsi(m_emm_ctx.imsi); m_nas_log->debug("Allocated GUTI: MCC %d, MNC %d, MME Group Id %d, MME Code 0x%x, M-TMSI 0x%x\n", attach_accept.guti.guti.mcc, @@ -722,8 +711,8 @@ nas::pack_attach_accept(srslte::byte_buffer_t *nas_buffer) //Set up LAI for combined EPS/IMSI attach attach_accept.lai_present=true; - attach_accept.lai.mcc = mcc; - attach_accept.lai.mnc = mnc; + attach_accept.lai.mcc = m_mcc; + attach_accept.lai.mnc = m_mnc; attach_accept.lai.lac = 001; attach_accept.ms_id_present=true; @@ -743,12 +732,12 @@ nas::pack_attach_accept(srslte::byte_buffer_t *nas_buffer) //Set activate default eps bearer (esm_ms) //Set pdn_addr act_def_eps_bearer_context_req.pdn_addr.pdn_type = LIBLTE_MME_PDN_TYPE_IPV4; - memcpy(act_def_eps_bearer_context_req.pdn_addr.addr, &paa->ipv4, 4); + memcpy(act_def_eps_bearer_context_req.pdn_addr.addr, &m_emm_ctx.ue_ip.s_addr, 4); //Set eps bearer id - act_def_eps_bearer_context_req.eps_bearer_id = erab_ctxt->e_RAB_ID.E_RAB_ID; + act_def_eps_bearer_context_req.eps_bearer_id = 5; act_def_eps_bearer_context_req.transaction_id_present = false; //set eps_qos - act_def_eps_bearer_context_req.eps_qos.qci = erab_ctxt->e_RABlevelQoSParameters.qCI.QCI; + act_def_eps_bearer_context_req.eps_qos.qci = m_esm_ctx[5].qci; //set apn strncpy(act_def_eps_bearer_context_req.apn.apn, m_apn.c_str(), LIBLTE_STRING_LEN); @@ -761,7 +750,7 @@ nas::pack_attach_accept(srslte::byte_buffer_t *nas_buffer) act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].len = 4; struct sockaddr_in dns_addr; - inet_pton(AF_INET, m_s1ap->m_s1ap_args.dns_addr.c_str(), &(dns_addr.sin_addr)); + inet_pton(AF_INET, m_dns.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); //Make sure all unused options are set to false @@ -792,10 +781,9 @@ nas::pack_attach_accept(srslte::byte_buffer_t *nas_buffer) m_nas_log->info("Packed Attach Complete\n"); //Add nas message to context setup request - erab_ctxt->nAS_PDU_present = true; - memcpy(erab_ctxt->nAS_PDU.buffer, nas_buffer->msg, nas_buffer->N_bytes); - erab_ctxt->nAS_PDU.n_octets = nas_buffer->N_bytes; - + //erab_ctxt->nAS_PDU_present = true; + //memcpy(erab_ctxt->nAS_PDU.buffer, nas_buffer->msg, nas_buffer->N_bytes); + //erab_ctxt->nAS_PDU.n_octets = nas_buffer->N_bytes; return true; } diff --git a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc index 231867055..817f943cf 100644 --- a/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_ctx_mngmt_proc.cc @@ -233,7 +233,7 @@ s1ap_ctx_mngmt_proc::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_I 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(emm_ctx->imsi, &nas_ctx->m_esm_ctx[5]); + m_mme_gtpc->send_modify_bearer_request(emm_ctx->imsi, 5, &nas_ctx->m_esm_ctx[5].enb_fteid); } return true; }