diff --git a/srsepc/hdr/mme/nas.h b/srsepc/hdr/mme/nas.h index 69821d558..51a561355 100644 --- a/srsepc/hdr/mme/nas.h +++ b/srsepc/hdr/mme/nas.h @@ -221,9 +221,29 @@ public: gtpc_interface_nas *gtpc, hss_interface_nas *hss, srslte::log *nas_log); + //Dettach request messages + static bool handle_detach_request( uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + struct sctp_sndrcvinfo *enb_sri, + srslte::byte_buffer_t *nas_rx, + nas_init_t args, + s1ap_interface_nas *s1ap, + gtpc_interface_nas *gtpc, + hss_interface_nas *hss, + srslte::log *nas_log); + //Tracking area update request messages - + static bool handle_tracking_area_update_request( uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + struct sctp_sndrcvinfo *enb_sri, + srslte::byte_buffer_t *nas_rx, + nas_init_t args, + s1ap_interface_nas *s1ap, + gtpc_interface_nas *gtpc, + hss_interface_nas *hss, + srslte::log *nas_log); + /* 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); @@ -232,7 +252,7 @@ public: bool handle_identity_response (srslte::byte_buffer_t *nas_rx); bool handle_tracking_area_update_request (srslte::byte_buffer_t *nas_rx); bool handle_authentication_failure (srslte::byte_buffer_t *nas_rx); - bool handle_nas_detach_request (srslte::byte_buffer_t *nas_rx); + bool handle_detach_request (srslte::byte_buffer_t *nas_rx); /* Downlink NAS messages packing */ bool pack_authentication_request (srslte::byte_buffer_t *nas_buffer); diff --git a/srsepc/src/mme/nas.cc b/srsepc/src/mme/nas.cc index afa6e5067..02a72908d 100644 --- a/srsepc/src/mme/nas.cc +++ b/srsepc/src/mme/nas.cc @@ -505,15 +505,16 @@ nas::handle_guti_attach_request_known_ue( nas *nas_ctx, } //Service Requests - bool nas::handle_service_request( uint32_t m_tmsi, - uint32_t enb_ue_s1ap_id, - struct sctp_sndrcvinfo *enb_sri, - srslte::byte_buffer_t *nas_rx, - nas_init_t args, - s1ap_interface_nas *s1ap, - gtpc_interface_nas *gtpc, - hss_interface_nas *hss, - srslte::log *nas_log) +bool +nas::handle_service_request( uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + struct sctp_sndrcvinfo *enb_sri, + srslte::byte_buffer_t *nas_rx, + nas_init_t args, + s1ap_interface_nas *s1ap, + gtpc_interface_nas *gtpc, + hss_interface_nas *hss, + srslte::log *nas_log) { nas_log->info("Service request -- S-TMSI 0x%x\n", m_tmsi); nas_log->console("Service request -- S-TMSI 0x%x\n", m_tmsi); @@ -615,6 +616,96 @@ nas::handle_guti_attach_request_known_ue( nas *nas_ctx, return true; } +bool nas::handle_detach_request( uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + struct sctp_sndrcvinfo *enb_sri, + srslte::byte_buffer_t *nas_rx, + nas_init_t args, + s1ap_interface_nas *s1ap, + gtpc_interface_nas *gtpc, + hss_interface_nas *hss, + srslte::log *nas_log) +{ + nas_log->info("Detach Request -- S-TMSI 0x%x\n", m_tmsi); + nas_log->console("Detach Request -- S-TMSI 0x%x\n", m_tmsi); + nas_log->info("Detach Request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); + nas_log->console("Detach Request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); + + 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_rx, &detach_req); + if (err !=LIBLTE_SUCCESS) { + nas_log->error("Could not unpack detach request\n"); + return false; + } + + uint64_t imsi = s1ap->find_imsi_from_m_tmsi(m_tmsi); + if (imsi == 0) { + nas_log->console("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + nas_log->error("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + return true; + } + + nas *nas_ctx = s1ap->find_nas_ctx_from_imsi(imsi); + if (nas_ctx == NULL) { + nas_log->console("Could not find UE context from IMSI\n"); + nas_log->error("Could not find UE context from IMSI\n"); + return true; + } + + emm_ctx_t *emm_ctx = &nas_ctx->m_emm_ctx; + ecm_ctx_t *ecm_ctx = &nas_ctx->m_ecm_ctx; + sec_ctx_t *sec_ctx = &nas_ctx->m_sec_ctx; + + gtpc->send_delete_session_request(emm_ctx->imsi); + emm_ctx->state = EMM_STATE_DEREGISTERED; + sec_ctx->ul_nas_count++; + + nas_log->console("Received. M-TMSI 0x%x\n", m_tmsi); + //Received detach request as an initial UE message + //eNB created new ECM context to send the detach request; this needs to be cleared. + ecm_ctx->mme_ue_s1ap_id = s1ap->get_next_mme_ue_s1ap_id(); + ecm_ctx->enb_ue_s1ap_id = enb_ue_s1ap_id; + s1ap->send_ue_context_release_command(ecm_ctx->mme_ue_s1ap_id); + return true; +} + +bool +nas::handle_tracking_area_update_request( uint32_t m_tmsi, + uint32_t enb_ue_s1ap_id, + struct sctp_sndrcvinfo *enb_sri, + srslte::byte_buffer_t *nas_rx, + nas_init_t args, + s1ap_interface_nas *s1ap, + gtpc_interface_nas *gtpc, + hss_interface_nas *hss, + srslte::log *nas_log) +{ + nas_log->info("Tracking Area Update Request -- S-TMSI 0x%x\n", m_tmsi); + nas_log->console("Tracking Area Update Request -- S-TMSI 0x%x\n", m_tmsi); + nas_log->info("Tracking Area Update Request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); + nas_log->console("Tracking Area Update Request -- eNB UE S1AP Id %d\n", enb_ue_s1ap_id); + + nas_log->console("Warning: Tracking area update requests are not handled yet.\n"); + nas_log->warning("Tracking area update requests are not handled yet.\n"); + + uint64_t imsi = s1ap->find_imsi_from_m_tmsi(m_tmsi); + if (imsi == 0) { + nas_log->console("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + nas_log->error("Could not find IMSI from M-TMSI. M-TMSI 0x%x\n", m_tmsi); + return true; + } + + nas *nas_ctx = s1ap->find_nas_ctx_from_imsi(imsi); + emm_ctx_t *emm_ctx = &nas_ctx->m_emm_ctx; + ecm_ctx_t *ecm_ctx = &nas_ctx->m_ecm_ctx; + + sec_ctx_t *sec_ctx = &nas_ctx->m_sec_ctx; + + sec_ctx->ul_nas_count++; //Increment the NAS count, not to break the security ctx + return true; +} /*************************************** * * Handle Uplink NAS Transport messages @@ -916,7 +1007,7 @@ nas::handle_authentication_failure(srslte::byte_buffer_t *nas_rx) } bool -nas::handle_nas_detach_request(srslte::byte_buffer_t *nas_msg) +nas::handle_detach_request(srslte::byte_buffer_t *nas_msg) { m_nas_log->console("Detach request -- IMSI %015lu\n", m_emm_ctx.imsi); diff --git a/srsepc/src/mme/s1ap_nas_transport.cc b/srsepc/src/mme/s1ap_nas_transport.cc index 2874fe16d..e42fa3d29 100644 --- a/srsepc/src/mme/s1ap_nas_transport.cc +++ b/srsepc/src/mme/s1ap_nas_transport.cc @@ -115,23 +115,25 @@ s1ap_nas_transport::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSA m_s1ap_log->console("Received Initial UE message -- Attach Request\n"); m_s1ap_log->info("Received Initial UE message -- Attach Request\n"); err = nas::handle_attach_request(enb_ue_s1ap_id, enb_sri, nas_msg, nas_init, - m_s1ap, m_mme_gtpc, m_hss, m_s1ap->m_nas_log); + m_s1ap, m_mme_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"); m_s1ap_log->info("Received Initial UE message -- Service Request\n"); err = nas::handle_service_request(m_tmsi, enb_ue_s1ap_id, enb_sri, nas_msg, nas_init, - m_s1ap, m_mme_gtpc, m_hss, m_s1ap->m_nas_log); + m_s1ap, m_mme_gtpc, m_hss, m_s1ap->m_nas_log); break; case LIBLTE_MME_MSG_TYPE_DETACH_REQUEST: m_s1ap_log->console("Received Initial UE message -- Detach Request\n"); m_s1ap_log->info("Received Initial UE message -- Detach Request\n"); - err = handle_nas_detach_request(m_tmsi, enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); + err = nas::handle_detach_request(m_tmsi, enb_ue_s1ap_id, enb_sri, nas_msg, nas_init, + m_s1ap, m_mme_gtpc, m_hss, m_s1ap->m_nas_log); break; case LIBLTE_MME_MSG_TYPE_TRACKING_AREA_UPDATE_REQUEST: m_s1ap_log->console("Received Initial UE message -- Tracking Area Update Request\n"); m_s1ap_log->info("Received Initial UE message -- Tracking Area Update Request\n"); - err = handle_nas_tracking_area_update_request(m_tmsi, enb_ue_s1ap_id, nas_msg, reply_buffer,reply_flag, enb_sri); + err = nas::handle_tracking_area_update_request(m_tmsi, enb_ue_s1ap_id, enb_sri, nas_msg, nas_init, + m_s1ap, m_mme_gtpc, m_hss, m_s1ap->m_nas_log); break; default: m_s1ap_log->info("Unhandled Initial UE Message 0x%x \n", msg_type); @@ -215,11 +217,11 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA case LIBLTE_MME_MSG_TYPE_DETACH_REQUEST: m_s1ap_log->info("Plain Protected UL NAS: Detach Request\n"); m_s1ap_log->console("Plain Protected UL NAS: Detach Request\n"); - nas_ctx->handle_nas_detach_request(nas_msg); + nas_ctx->handle_detach_request(nas_msg); break; 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_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; } @@ -282,7 +284,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"); - nas_ctx->handle_nas_detach_request(nas_msg); + nas_ctx->handle_detach_request(nas_msg); break; default: m_s1ap_log->warning("Unhandled NAS integrity protected message %s\n", liblte_nas_msg_type_to_string(msg_type)); @@ -299,86 +301,6 @@ s1ap_nas_transport::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRA 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) -{ - m_s1ap_log->info("Detach Request -- S-TMSI 0x%x\n", m_tmsi); - m_s1ap_log->console("Detach Request -- S-TMSI 0x%x\n", 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); - - 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; - } - - nas *nas_ctx = m_s1ap->find_nas_ctx_from_imsi(it->second); - emm_ctx_t *emm_ctx = &nas_ctx->m_emm_ctx; - ecm_ctx_t *ecm_ctx = &nas_ctx->m_ecm_ctx; - sec_ctx_t *sec_ctx = &nas_ctx->m_sec_ctx; - - m_mme_gtpc->send_delete_session_request(emm_ctx->imsi); - emm_ctx->state = EMM_STATE_DEREGISTERED; - sec_ctx->ul_nas_count++; - - m_s1ap_log->console("Received. M-TMSI 0x%x\n", m_tmsi); - //Received detach request as an initial UE message - //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(nas_ctx); - 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->info("Tracking Area Update Request -- S-TMSI 0x%x\n", m_tmsi); - m_s1ap_log->console("Tracking Area Update Request -- S-TMSI 0x%x\n", 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); - - 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; - } - - nas *nas_ctx = m_s1ap->find_nas_ctx_from_imsi(it->second); - emm_ctx_t *emm_ctx = &nas_ctx->m_emm_ctx; - ecm_ctx_t *ecm_ctx = &nas_ctx->m_ecm_ctx; - - sec_ctx_t *sec_ctx = &nas_ctx->m_sec_ctx; - - sec_ctx->ul_nas_count++; //Increment the NAS count, not to break the security ctx - return true; -} - bool s1ap_nas_transport::send_downlink_nas_transport(uint32_t enb_ue_s1ap_id, uint32_t mme_ue_s1ap_id, srslte::byte_buffer_t *nas_msg, struct sctp_sndrcvinfo enb_sri) {