From 9e808ff9681be65ec8692dda9958d273861e6d35 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 24 Aug 2018 18:15:06 +0100 Subject: [PATCH] Starting to handle NAS initial UE messages as static methods of the nas class. --- srsepc/hdr/mme/nas.h | 97 ++++++---- srsepc/src/mme/nas.cc | 276 ++++++++++++--------------- srsepc/src/mme/s1ap_nas_transport.cc | 45 +---- 3 files changed, 196 insertions(+), 222 deletions(-) diff --git a/srsepc/hdr/mme/nas.h b/srsepc/hdr/mme/nas.h index 9eb7c5ad3..4c419cb06 100644 --- a/srsepc/hdr/mme/nas.h +++ b/srsepc/hdr/mme/nas.h @@ -131,55 +131,76 @@ typedef struct{ LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT guti; } sec_ctx_t; +/* + * NAS Initialization Arguments + */ +typedef struct { + uint16_t mcc; + uint16_t mnc; + uint8_t mme_code; + uint16_t mme_group; + uint16_t tac; + std::string apn; + std::string dns; +} nas_init_t; + class nas { public: nas(); - void init(uint16_t mcc, - uint16_t mnc, - uint8_t mme_code, - uint16_t mme_group, - uint16_t tac, - std::string apn, - std::string dns, + void init(nas_init_t args, s1ap_interface_nas *s1ap, gtpc_interface_nas *gtpc, hss_interface_nas *hss, srslte::log *nas_log); - /*Initial UE messages*/ - bool handle_attach_request( 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_imsi_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, - struct sctp_sndrcvinfo *enb_sri); - - bool handle_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); + /*********************** + * Initial UE messages * + ***********************/ + //Attach request messages + static bool handle_attach_request( uint32_t enb_ue_s1ap_id, + struct sctp_sndrcvinfo *enb_sri, + srslte::byte_buffer_t *nas_msg, + nas_init_t args, + s1ap_interface_nas *s1ap, + gtpc_interface_nas *gtpc, + hss_interface_nas *hss, + srslte::log *nas_log); + + static bool handle_imsi_attach_request_unknown_ue( uint32_t enb_ue_s1ap_id, + struct sctp_sndrcvinfo *enb_sri, + const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, + const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + nas_init_t args, + s1ap_interface_nas *s1ap, + gtpc_interface_nas *gtpc, + hss_interface_nas *hss, + srslte::log *nas_log); + + bool handle_imsi_attach_request_known_ue( uint32_t enb_ue_s1ap_id, + struct sctp_sndrcvinfo *enb_sri, + const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, + const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req); + + + static bool handle_guti_attach_request_unknown_ue( uint32_t enb_ue_s1ap_id, + struct sctp_sndrcvinfo *enb_sri, + const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, + const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + nas_init_t args, + s1ap_interface_nas *s1ap, + gtpc_interface_nas *gtpc, + hss_interface_nas *hss, + srslte::log *nas_log); bool handle_guti_attach_request_known_ue( uint32_t enb_ue_s1ap_id, + struct sctp_sndrcvinfo *enb_sri, 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_rx, - struct sctp_sndrcvinfo *enb_sri); - - bool handle_guti_attach_request_unknown_ue( 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); + const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req); + + //Service request Messages + //Dettach request Messages + // /* Uplink NAS messages handling */ bool handle_authentication_response( srslte::byte_buffer_t *nas_rx); bool handle_security_mode_complete( srslte::byte_buffer_t *nas_rx); @@ -204,7 +225,7 @@ public: bool integrity_check (srslte::byte_buffer_t *pdu); bool short_integrity_check (srslte::byte_buffer_t *pdu); - /* UE Context*/ + /* UE Context */ emm_ctx_t m_emm_ctx; ecm_ctx_t m_ecm_ctx; esm_ctx_t m_esm_ctx[MAX_ERABS_PER_UE]; diff --git a/srsepc/src/mme/nas.cc b/srsepc/src/mme/nas.cc index 63a3da39a..def9f3f6c 100644 --- a/srsepc/src/mme/nas.cc +++ b/srsepc/src/mme/nas.cc @@ -40,25 +40,19 @@ nas::nas() { } void -nas::init(uint16_t mcc, - uint16_t mnc, - uint8_t mme_code, - uint16_t mme_group, - uint16_t tac, - std::string apn, - std::string dns, +nas::init(nas_init_t args, s1ap_interface_nas *s1ap, gtpc_interface_nas *gtpc, hss_interface_nas *hss, srslte::log *nas_log) { - m_mcc = mcc; - m_mnc = mnc; - m_mme_code = mme_code; - m_mme_group = mme_group; - m_tac = tac; - m_apn = apn; - m_dns = dns; + m_mcc = args.mcc; + m_mnc = args.mnc; + m_mme_code = args.mme_code; + m_mme_group = args.mme_group; + m_tac = args.tac; + m_apn = args.apn; + m_dns = args.dns; m_s1ap = s1ap; m_gtpc = gtpc; @@ -71,80 +65,136 @@ nas::init(uint16_t mcc, * Handle UE Initiating Messages * ********************************/ -//FIXME Move UE Initiating mesages from s1ap_nas_transport -bool +static bool nas::handle_attach_request( uint32_t enb_ue_s1ap_id, + struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *nas_msg, - srslte::byte_buffer_t *reply_buffer, - bool* reply_flag, - struct sctp_sndrcvinfo *enb_sri) + nas_init_t args, + s1ap_interface_nas *s1ap, + gtpc_interface_nas *gtpc, + hss_interface_nas *hss, + srslte::log *nas_log) { - bool save = true; + uint32_t m_tmsi = 0; + uint64_t imsi = 0; 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_nas_log->error("Error unpacking NAS attach request. Error: %s\n", liblte_error_text[err]); - return save; + nas_log->error("Error unpacking NAS attach request. Error: %s\n", liblte_error_text[err]); + return false; } - /*Get PDN Connectivity Request*/ + //Get PDN Connectivity Request*/ err = liblte_mme_unpack_pdn_connectivity_request_msg(&attach_req.esm_msg, &pdn_con_req); if(err != LIBLTE_SUCCESS){ - m_nas_log->error("Error unpacking NAS PDN Connectivity Request. Error: %s\n", liblte_error_text[err]); - return save; + nas_log->error("Error unpacking NAS PDN Connectivity Request. Error: %s\n", liblte_error_text[err]); + return false; } - //Get attach type from attach request + //Get UE IMSI if (attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMSI) { - m_nas_log->console("Attach Request -- IMSI-style attach request\n"); - m_nas_log->info("Attach Request -- IMSI-style attach request\n"); - save = handle_imsi_attach_request(enb_ue_s1ap_id, attach_req, pdn_con_req, enb_sri); + for(int i=0;i<=14;i++){ + imsi += attach_req.eps_mobile_id.imsi[i]*std::pow(10,14-i); + } + nas_log->console("Attach request -- IMSI Style Attach request\n"); + nas_log->info("Attach request -- IMSI Style Attach request\n"); + nas_log->console("Attach request -- IMSI: %015lu\n", imsi); + nas_log->info("Attach request -- IMSI: %015lu\n", imsi); } else if (attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_GUTI) { - m_nas_log->console("Attach Request -- GUTI-style attach request\n"); - m_nas_log->info("Attach Request -- GUTI-style attach request\n"); - save = handle_guti_attach_request(enb_ue_s1ap_id, attach_req, pdn_con_req, nas_msg, reply_buffer, reply_flag, enb_sri); + m_tmsi = attach_req.eps_mobile_id.guti.m_tmsi; + imsi = s1ap->find_imsi_from_m_tmsi(m_tmsi); + nas_log->console("Attach request -- GUTI Style Attach request\n"); + nas_log->info("Attach request -- GUTI Style Attach request\n"); + nas_log->console("Attach request -- M-TMSI: 0x%x\n", m_tmsi); + nas_log->info("Attach request -- M-TMSI: 0x%x\n", m_tmsi); } else { - m_nas_log->error("Unhandled Mobile Id type in attach request\n"); - return save; + nas_log->error("Unhandled Mobile Id type in attach request\n"); + return false; } - //Log Attach Request information - m_nas_log->console("Attach request -- IMSI: %015lu\n", m_emm_ctx.imsi); - m_nas_log->info("Attach request -- IMSI: %015lu\n", m_emm_ctx.imsi); - m_nas_log->console("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id); - m_nas_log->info("Attach request -- eNB-UE S1AP Id: %d, MME-UE S1AP Id: %d\n", m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id); - m_nas_log->console("Attach request -- Attach type: %d\n", attach_req.eps_attach_type); - m_nas_log->info("Attach request -- Attach type: %d\n", attach_req.eps_attach_type); - m_nas_log->console("Attach Request -- UE Network Capabilities EEA: %d%d%d%d%d%d%d%d\n", + //Log Attach Request Information + nas_log->console("Attach request -- eNB-UE S1AP Id: %d\n", enb_ue_s1ap_id); + nas_log->info("Attach request -- eNB-UE S1AP Id: %d\n", enb_ue_s1ap_id); + nas_log->console("Attach request -- Attach type: %d\n", attach_req.eps_attach_type); + nas_log->info("Attach request -- Attach type: %d\n", attach_req.eps_attach_type); + nas_log->console("Attach Request -- UE Network Capabilities EEA: %d%d%d%d%d%d%d%d\n", attach_req.ue_network_cap.eea[0], attach_req.ue_network_cap.eea[1], attach_req.ue_network_cap.eea[2], attach_req.ue_network_cap.eea[3], attach_req.ue_network_cap.eea[4], attach_req.ue_network_cap.eea[5], attach_req.ue_network_cap.eea[6], attach_req.ue_network_cap.eea[7]); - m_nas_log->info("Attach Request -- UE Network Capabilities EEA: %d%d%d%d%d%d%d%d\n", - attach_req.ue_network_cap.eea[0], attach_req.ue_network_cap.eea[1], attach_req.ue_network_cap.eea[2], attach_req.ue_network_cap.eea[3], - attach_req.ue_network_cap.eea[4], attach_req.ue_network_cap.eea[5], attach_req.ue_network_cap.eea[6], attach_req.ue_network_cap.eea[7]); - m_nas_log->console("Attach Request -- UE Network Capabilities EIA: %d%d%d%d%d%d%d%d\n", - attach_req.ue_network_cap.eia[0], attach_req.ue_network_cap.eia[1], attach_req.ue_network_cap.eia[2], attach_req.ue_network_cap.eia[3], - attach_req.ue_network_cap.eia[4], attach_req.ue_network_cap.eia[5], attach_req.ue_network_cap.eia[6], attach_req.ue_network_cap.eia[7]); - m_nas_log->info("Attach Request -- UE Network Capabilities EIA: %d%d%d%d%d%d%d%d\n", - attach_req.ue_network_cap.eia[0], attach_req.ue_network_cap.eia[1], attach_req.ue_network_cap.eia[2], attach_req.ue_network_cap.eia[3], - attach_req.ue_network_cap.eia[4], attach_req.ue_network_cap.eia[5], attach_req.ue_network_cap.eia[6], attach_req.ue_network_cap.eia[7]); - m_nas_log->console("Attach Request -- MS Network Capabilities Present: %s\n", attach_req.ms_network_cap_present ? "true" : "false"); - m_nas_log->info("Attach Request -- MS Network Capabilities Present: %s\n", attach_req.ms_network_cap_present ? "true" : "false"); - m_nas_log->console("PDN Connectivity Request -- EPS Bearer Identity requested: %d\n", pdn_con_req.eps_bearer_id); - m_nas_log->info("PDN Connectivity Request -- EPS Bearer Identity requested: %d\n", pdn_con_req.eps_bearer_id); - m_nas_log->console("PDN Connectivity Request -- Procedure Transaction Id: %d\n", pdn_con_req.proc_transaction_id); - m_nas_log->info("PDN Connectivity Request -- Procedure Transaction Id: %d\n", pdn_con_req.proc_transaction_id); - m_nas_log->console("PDN Connectivity Request -- ESM Information Transfer requested: %s\n", pdn_con_req.esm_info_transfer_flag_present ? "true" : "false"); - m_nas_log->info("PDN Connectivity Request -- ESM Information Transfer requested: %s\n", pdn_con_req.esm_info_transfer_flag_present ? "true" : "false"); - return save; + nas_log->info("Attach Request -- UE Network Capabilities EEA: %d%d%d%d%d%d%d%d\n", + attach_req.ue_network_cap.eea[0], attach_req.ue_network_cap.eea[1], attach_req.ue_network_cap.eea[2], attach_req.ue_network_cap.eea[3], + attach_req.ue_network_cap.eea[4], attach_req.ue_network_cap.eea[5], attach_req.ue_network_cap.eea[6], attach_req.ue_network_cap.eea[7]); + nas_log->console("Attach Request -- UE Network Capabilities EIA: %d%d%d%d%d%d%d%d\n", + attach_req.ue_network_cap.eia[0], attach_req.ue_network_cap.eia[1], attach_req.ue_network_cap.eia[2], attach_req.ue_network_cap.eia[3], + attach_req.ue_network_cap.eia[4], attach_req.ue_network_cap.eia[5], attach_req.ue_network_cap.eia[6], attach_req.ue_network_cap.eia[7]); + nas_log->info("Attach Request -- UE Network Capabilities EIA: %d%d%d%d%d%d%d%d\n", + attach_req.ue_network_cap.eia[0], attach_req.ue_network_cap.eia[1], attach_req.ue_network_cap.eia[2], attach_req.ue_network_cap.eia[3], + attach_req.ue_network_cap.eia[4], attach_req.ue_network_cap.eia[5], attach_req.ue_network_cap.eia[6], attach_req.ue_network_cap.eia[7]); + nas_log->console("Attach Request -- MS Network Capabilities Present: %s\n", attach_req.ms_network_cap_present ? "true" : "false"); + nas_log->info("Attach Request -- MS Network Capabilities Present: %s\n", attach_req.ms_network_cap_present ? "true" : "false"); + nas_log->console("PDN Connectivity Request -- EPS Bearer Identity requested: %d\n", pdn_con_req.eps_bearer_id); + nas_log->info("PDN Connectivity Request -- EPS Bearer Identity requested: %d\n", pdn_con_req.eps_bearer_id); + nas_log->console("PDN Connectivity Request -- Procedure Transaction Id: %d\n", pdn_con_req.proc_transaction_id); + nas_log->info("PDN Connectivity Request -- Procedure Transaction Id: %d\n", pdn_con_req.proc_transaction_id); + nas_log->console("PDN Connectivity Request -- ESM Information Transfer requested: %s\n", pdn_con_req.esm_info_transfer_flag_present ? "true" : "false"); + nas_log->info("PDN Connectivity Request -- ESM Information Transfer requested: %s\n", pdn_con_req.esm_info_transfer_flag_present ? "true" : "false"); + + //Get NAS Context if UE is known + nas * nas_ctx = s1ap->find_nas_ctx_from_imsi(imsi); + if (nas_ctx == NULL) + { + //Get attach type from attach request + if (attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMSI) { + nas_log->console("Attach Request -- IMSI-style attach request\n"); + nas_log->info("Attach Request -- IMSI-style attach request\n"); + nas::handle_imsi_attach_request_unknown_ue(enb_ue_s1ap_id, enb_sri, attach_req, pdn_con_req, args, s1ap, gtpc, hss, nas_log); + } else if (attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_GUTI) { + nas_log->console("Attach Request -- GUTI-style attach request\n"); + nas_log->info("Attach Request -- GUTI-style attach request\n"); + nas::handle_guti_attach_request_unknown_ue(enb_ue_s1ap_id, enb_sri, attach_req, pdn_con_req, args, s1ap, gtpc, hss, nas_log); + } else { + nas_log->error("Unhandled Mobile Id type in attach request\n"); + return false; + } + } else { + if (attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMSI) { + nas_log->console("Attach Request -- IMSI-style attach request\n"); + nas_log->info("Attach Request -- IMSI-style attach request\n"); + nas_ctx->handle_imsi_attach_request_known_ue(enb_ue_s1ap_id, enb_sri, attach_req, pdn_con_req); + } else if (attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_GUTI) { + nas_log->console("Attach Request -- GUTI-style attach request\n"); + nas_log->info("Attach Request -- GUTI-style attach request\n"); + nas_ctx->handle_guti_attach_request_known_ue(enb_ue_s1ap_id, enb_sri, attach_req, pdn_con_req); + } else { + nas_log->error("Unhandled Mobile Id type in attach request\n"); + return false; + } + } + + //Log Attach Request information + return true; } +static bool +nas::handle_imsi_attach_request_unknown_ue( uint32_t enb_ue_s1ap_id, + struct sctp_sndrcvinfo *enb_sri, + const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, + const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + nas_init_t args, + s1ap_interface_nas *s1ap, + gtpc_interface_nas *gtpc, + hss_interface_nas *hss, + srslte::log *nas_log) + +{ + return true; +} bool -nas::handle_imsi_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, - struct sctp_sndrcvinfo *enb_sri) +nas::handle_imsi_attach_request_known_ue( uint32_t enb_ue_s1ap_id, + struct sctp_sndrcvinfo *enb_sri, + 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_tx; @@ -218,86 +268,11 @@ nas::handle_imsi_attach_request( uint32_t enb_ue_s1ap_id, return true; } -bool -nas::handle_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) -{ - //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_nas_log->info("Attach request -- GUTI-stlye attach request is not integrity protected\n"); - m_nas_log->console("Attach request -- GUTI-stlye attach request is not integrity protected\n"); - } else { - m_nas_log->info("Attach request -- GUTI-stlye attach request is integrity protected\n"); - m_nas_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); - if (it == m_s1ap->m_tmsi_to_imsi.end()) { - //Could not find IMSI from M-TMSI, send Id request - 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); - - //nas *nas_ctx = new nas; - //nas_ctx->init(m_s1ap->m_s1ap_args.mcc, - // m_s1ap->m_s1ap_args.mnc, - // m_s1ap->m_s1ap_args.mme_code, - // m_s1ap->m_s1ap_args.mme_group, - // m_s1ap->m_s1ap_args.tac, - // m_s1ap->m_s1ap_args.mme_apn, - // m_s1ap->m_s1ap_args.dns_addr, - // m_s1ap, m_mme_gtpc, m_hss, m_s1ap->m_nas_log); - - bool err = nas_ctx->handle_guti_attach_request_unknown_ue( enb_ue_s1ap_id, - attach_req, - pdn_con_req, - nas_msg, - reply_buffer, - reply_flag, - enb_sri); - //if (err == false) { - // delete nas_ctx; - //} - return err; - } else { - //Found UE context from M-TMSI - m_nas_log->console("Attach Request -- Found M-TMSI: %d\n",m_tmsi); - m_nas_log->console("Attach Request -- IMSI: %015lu\n",it->second); - //Get UE EMM context - nas *nas_ctx = m_s1ap->find_nas_ctx_from_imsi(it->second); - if (nas_ctx!=NULL) { - nas_ctx->handle_guti_attach_request_known_ue( enb_ue_s1ap_id, - attach_req, - pdn_con_req, - nas_msg, - reply_buffer, - reply_flag, - enb_sri); - } else { - m_s1ap_log->error("Found M-TMSI but could not find UE context\n"); - m_s1ap_log->console("Error: Found M-TMSI but could not find UE context\n"); - return false; - } - }*/ - return true; -} bool nas::handle_guti_attach_request_known_ue( 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_rx, - struct sctp_sndrcvinfo *enb_sri) + struct sctp_sndrcvinfo *enb_sri, + const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, + const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req) { m_nas_log->console("Found UE context. IMSI: %015lu, old eNB UE S1ap Id %d, old MME UE S1AP Id %d\n",m_emm_ctx.imsi, m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id); @@ -432,14 +407,17 @@ nas::handle_guti_attach_request_known_ue( uint32_t enb_ue_s1ap_id, } } -bool +static bool nas::handle_guti_attach_request_unknown_ue( 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) + struct sctp_sndrcvinfo *enb_sri, + const LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT &attach_req, + const LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT &pdn_con_req, + nas_init_t args, + s1ap_interface_nas *s1ap, + gtpc_interface_nas *gtpc, + hss_interface_nas *hss, + srslte::log *nas_log) + { srslte::byte_buffer_t *nas_tx; diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 09009d4a9..4bed610d4 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -96,47 +96,22 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA m_s1ap_log->console("Initial UE message: %s\n", liblte_nas_msg_type_to_string(msg_type)); m_s1ap_log->info ("Initial UE message: %s\n", liblte_nas_msg_type_to_string(msg_type)); - //Make sure M-TMSI is present, if mandatory - if (msg_type != LIBLTE_MME_MSG_TYPE_ATTACH_REQUEST && !init_ue->S_TMSI_present){ - m_s1ap_log->error("Initial UE Message 0x%x -- S-TMSI not present\n", msg_type); - m_s1ap_log->console("Initial UE message 0x%x -- S-TMSI not present\n", msg_type); - m_pool->deallocate(nas_msg); - return false; - } - - //Get NAS context if TMSI is present - nas *nas_ctx = NULL; - if (init_ue->S_TMSI_present) { - m_tmsi = ntohl(*((uint32_t*)&init_ue->S_TMSI.m_TMSI.buffer)); - imsi = m_s1ap->find_imsi_from_m_tmsi(m_tmsi); - if(imsi !=0){ - nas_ctx = m_s1ap->find_nas_ctx_from_imsi(imsi); - } - } - - //Create new NAS context if Attach request without known NAS context - //This will be release if the attach request returns an error - if (msg_type == LIBLTE_MME_MSG_TYPE_ATTACH_REQUEST && nas_ctx == NULL) { - nas_ctx = new nas; - nas_ctx->init(m_s1ap->m_s1ap_args.mcc, - m_s1ap->m_s1ap_args.mnc, - m_s1ap->m_s1ap_args.mme_code, - m_s1ap->m_s1ap_args.mme_group, - m_s1ap->m_s1ap_args.tac, - m_s1ap->m_s1ap_args.mme_apn, - m_s1ap->m_s1ap_args.dns_addr, - m_s1ap, m_mme_gtpc, m_hss, m_s1ap->m_nas_log); - } + nas_init_t nas_init; + nas_init.mcc = m_s1ap->m_s1ap_args.mcc; + nas_init.mnc = m_s1ap->m_s1ap_args.mnc; + nas_init.mme_code = m_s1ap->m_s1ap_args.mme_code; + nas_init.mme_group = m_s1ap->m_s1ap_args.mme_group; + nas_init.tac = m_s1ap->m_s1ap_args.tac; + nas_init.mme_apn = m_s1ap->m_s1ap_args.mme_apn; + nas_init.dns_addr = m_s1ap->m_s1ap_args.dns_addr; switch (msg_type) { case LIBLTE_MME_MSG_TYPE_ATTACH_REQUEST: m_s1ap_log->console("Received Initial UE message -- Attach Request\n"); m_s1ap_log->info("Received Initial UE message -- Attach Request\n"); - err = handle_nas_attach_request(enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); - if (err == false) { - delete nas_ctx; - } + err = nas::handle_nas_attach_request(enb_ue_s1ap_id, nas_init, enb_sri, nas_msg, + m_s1ap, m_gtpc, m_hss, m_s1ap->m_nas_log); break; case LIBLTE_MME_SECURITY_HDR_TYPE_SERVICE_REQUEST: m_s1ap_log->console("Received Initial UE message -- Service Request\n");