open5gs/src/mme/mme-s11-handler.c

837 lines
26 KiB
C
Raw Normal View History

2019-06-19 09:04:57 +00:00
/*
* Copyright (C) 2019 by Sukchan Lee <acetcom@gmail.com>
*
* This file is part of Open5GS.
*
* This program 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.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2019-06-11 13:10:47 +00:00
#include "mme-event.h"
#include "mme-sm.h"
#include "mme-context.h"
2017-08-09 15:41:09 +00:00
2019-06-01 09:52:38 +00:00
#include "s1ap-path.h"
2019-06-11 13:10:47 +00:00
#include "mme-gtp-path.h"
#include "nas-path.h"
#include "mme-fd-path.h"
2019-06-20 09:20:32 +00:00
#include "sgsap-path.h"
#include "mme-path.h"
2017-08-10 08:02:07 +00:00
2019-06-11 13:10:47 +00:00
#include "mme-s11-build.h"
#include "mme-s11-handler.h"
void mme_s11_handle_create_session_response(
2019-09-13 12:07:47 +00:00
ogs_gtp_xact_t *xact, mme_ue_t *mme_ue,
ogs_gtp_create_session_response_t *rsp)
2017-04-12 12:44:18 +00:00
{
2019-04-27 14:54:30 +00:00
int rv;
uint8_t cause_value = 0;
2019-09-13 12:07:47 +00:00
ogs_gtp_f_teid_t *sgw_s11_teid = NULL;
ogs_gtp_f_teid_t *sgw_s1u_teid = NULL;
2017-04-12 12:44:18 +00:00
mme_bearer_t *bearer = NULL;
2017-09-01 12:35:45 +00:00
mme_sess_t *sess = NULL;
2019-09-13 12:07:47 +00:00
ogs_pdn_t *pdn = NULL;
2017-04-12 12:44:18 +00:00
2019-04-27 14:54:30 +00:00
ogs_assert(xact);
ogs_assert(rsp);
2017-04-12 12:44:18 +00:00
2019-04-27 14:54:30 +00:00
ogs_debug("[MME] Create Session Response");
2018-01-22 15:00:57 +00:00
if (!mme_ue) {
ogs_warn("No Context in TEID");
mme_ue = xact->data;
ogs_assert(mme_ue);
}
rv = ogs_gtp_xact_commit(xact);
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(rv == OGS_OK);
if (rsp->cause.presence) {
ogs_gtp_cause_t *cause = rsp->cause.data;
ogs_assert(cause);
cause_value = cause->value;
if (cause_value == OGS_GTP_CAUSE_REQUEST_ACCEPTED) {
if (rsp->bearer_contexts_created.cause.presence) {
cause = rsp->bearer_contexts_created.cause.data;
ogs_assert(cause);
cause_value = cause->value;
} else {
ogs_error("No Cause");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
}
}
} else {
ogs_error("No Cause");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
}
if (cause_value != OGS_GTP_CAUSE_REQUEST_ACCEPTED)
ogs_warn("Cause[%d] : No Accepted", cause_value);
2019-06-19 09:04:57 +00:00
if (rsp->sender_f_teid_for_control_plane.presence == 0) {
2019-04-27 14:54:30 +00:00
ogs_error("No S11 TEID");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
2017-04-12 12:44:18 +00:00
}
2019-06-19 09:04:57 +00:00
if (rsp->pdn_address_allocation.presence == 0) {
2019-04-27 14:54:30 +00:00
ogs_error("No PDN Address Allocation");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
2017-04-13 03:21:47 +00:00
}
2019-06-19 09:04:57 +00:00
if (rsp->bearer_contexts_created.s1_u_enodeb_f_teid.presence == 0) {
2019-04-27 14:54:30 +00:00
ogs_error("No S1U TEID");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
2017-04-12 12:44:18 +00:00
}
2019-06-19 09:04:57 +00:00
if (rsp->bearer_contexts_created.presence == 0) {
2019-04-27 14:54:30 +00:00
ogs_error("No Bearer");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
}
if (rsp->bearer_contexts_created.eps_bearer_id.presence == 0) {
2019-04-27 14:54:30 +00:00
ogs_error("No EPS Bearer ID");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
}
if (cause_value != OGS_GTP_CAUSE_REQUEST_ACCEPTED) {
mme_send_delete_session_or_mme_ue_context_release(mme_ue);
return;
}
2017-04-12 12:44:18 +00:00
bearer = mme_bearer_find_by_ue_ebi(mme_ue,
rsp->bearer_contexts_created.eps_bearer_id.u8);
ogs_expect_or_return(bearer);
sess = bearer->sess;
2019-04-27 14:54:30 +00:00
ogs_assert(sess);
pdn = sess->pdn;
2019-04-27 14:54:30 +00:00
ogs_assert(pdn);
/* Control Plane(UL) : SGW-S11 */
2017-04-12 12:44:18 +00:00
sgw_s11_teid = rsp->sender_f_teid_for_control_plane.data;
2017-09-01 12:35:45 +00:00
mme_ue->sgw_s11_teid = ntohl(sgw_s11_teid->teid);
2017-04-12 12:44:18 +00:00
2017-04-13 03:21:47 +00:00
memcpy(&pdn->paa, rsp->pdn_address_allocation.data,
rsp->pdn_address_allocation.len);
/* PCO */
2019-06-19 09:04:57 +00:00
if (rsp->protocol_configuration_options.presence) {
2019-09-13 12:07:47 +00:00
OGS_TLV_STORE_DATA(&sess->pgw_pco,
&rsp->protocol_configuration_options);
2017-04-13 03:21:47 +00:00
}
/* Data Plane(UL) : SGW-S1U */
2017-04-12 12:44:18 +00:00
sgw_s1u_teid = rsp->bearer_contexts_created.s1_u_enodeb_f_teid.data;
2017-04-13 10:15:53 +00:00
bearer->sgw_s1u_teid = ntohl(sgw_s1u_teid->teid);
2018-02-01 05:07:01 +00:00
2019-04-27 14:54:30 +00:00
ogs_debug(" MME_S11_TEID[%d] SGW_S11_TEID[%d]",
2018-02-01 05:07:01 +00:00
mme_ue->mme_s11_teid, mme_ue->sgw_s11_teid);
2019-04-27 14:54:30 +00:00
ogs_debug(" ENB_S1U_TEID[%d] SGW_S1U_TEID[%d]",
2018-02-01 05:07:01 +00:00
bearer->enb_s1u_teid, bearer->sgw_s1u_teid);
2019-09-13 12:07:47 +00:00
rv = ogs_gtp_f_teid_to_ip(sgw_s1u_teid, &bearer->sgw_s1u_ip);
2019-04-27 14:54:30 +00:00
ogs_assert(rv == OGS_OK);
2017-04-12 13:27:32 +00:00
2019-06-19 09:04:57 +00:00
if (OGS_FSM_CHECK(&mme_ue->sm, emm_state_initial_context_setup)) {
2019-07-21 11:25:29 +00:00
mme_csmap_t *csmap = mme_csmap_find_by_tai(&mme_ue->tai);
mme_ue->csmap = csmap;
2019-07-21 11:25:29 +00:00
if (csmap) {
2019-06-20 09:20:32 +00:00
sgsap_send_location_update_request(mme_ue);
2019-07-20 13:30:53 +00:00
} else {
2019-06-20 09:20:32 +00:00
nas_send_attach_accept(mme_ue);
2019-07-20 13:30:53 +00:00
}
2019-06-19 09:04:57 +00:00
} else if (OGS_FSM_CHECK(&mme_ue->sm, emm_state_registered)) {
2019-06-20 09:20:32 +00:00
nas_send_activate_default_bearer_context_request(bearer);
2019-06-19 09:04:57 +00:00
} else
2019-04-27 14:54:30 +00:00
ogs_assert_if_reached();
2017-04-12 12:44:18 +00:00
}
2017-04-13 16:26:50 +00:00
void mme_s11_handle_modify_bearer_response(
2019-09-13 12:07:47 +00:00
ogs_gtp_xact_t *xact, mme_ue_t *mme_ue,
ogs_gtp_modify_bearer_response_t *rsp)
{
2019-04-27 14:54:30 +00:00
int rv;
uint8_t cause_value = 0;
enb_ue_t *source_ue = NULL, *target_ue = NULL;
2019-04-27 14:54:30 +00:00
ogs_assert(xact);
ogs_assert(rsp);
2019-04-27 14:54:30 +00:00
ogs_debug("[MME] Modify Bearer Response");
if (!mme_ue) {
ogs_warn("No Context in TEID");
mme_ue = xact->data;
ogs_assert(mme_ue);
}
2019-09-13 12:07:47 +00:00
rv = ogs_gtp_xact_commit(xact);
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(rv == OGS_OK);
if (rsp->cause.presence) {
ogs_gtp_cause_t *cause = rsp->cause.data;
ogs_assert(cause);
cause_value = cause->value;
if (cause_value != OGS_GTP_CAUSE_REQUEST_ACCEPTED)
ogs_warn("GTP Failed [CAUSE:%d]", cause_value);
}
ogs_debug(" MME_S11_TEID[%d] SGW_S11_TEID[%d]",
mme_ue->mme_s11_teid, mme_ue->sgw_s11_teid);
if (cause_value != OGS_GTP_CAUSE_REQUEST_ACCEPTED) {
mme_send_delete_session_or_mme_ue_context_release(mme_ue);
return;
}
GTP_COUNTER_CHECK(mme_ue, GTP_COUNTER_MODIFY_BEARER_BY_PATH_SWITCH,
2019-11-30 07:45:09 +00:00
s1ap_send_path_switch_ack(mme_ue);
);
GTP_COUNTER_CHECK(mme_ue, GTP_COUNTER_MODIFY_BEARER_BY_HANDOVER_NOTIFY,
target_ue = mme_ue->enb_ue;
2019-04-27 14:54:30 +00:00
ogs_assert(target_ue);
source_ue = target_ue->source_ue;
2019-04-27 14:54:30 +00:00
ogs_assert(source_ue);
s1ap_send_ue_context_release_command(source_ue,
2018-03-05 14:01:07 +00:00
S1AP_Cause_PR_radioNetwork,
S1AP_CauseRadioNetwork_successful_handover,
2019-04-27 14:54:30 +00:00
S1AP_UE_CTX_REL_DELETE_INDIRECT_TUNNEL,
ogs_time_from_msec(300));
);
}
void mme_s11_handle_delete_session_response(
2019-09-13 12:07:47 +00:00
ogs_gtp_xact_t *xact, mme_ue_t *mme_ue,
ogs_gtp_delete_session_response_t *rsp)
{
2019-04-27 14:54:30 +00:00
int rv;
uint8_t cause_value = 0;
mme_sess_t *sess = NULL;
2019-04-27 14:54:30 +00:00
ogs_assert(xact);
ogs_assert(rsp);
2019-04-27 14:54:30 +00:00
ogs_debug("[MME] Delete Session Response");
sess = xact->data;
ogs_assert(sess);
mme_ue = sess->mme_ue;
ogs_assert(mme_ue);
rv = ogs_gtp_xact_commit(xact);
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(rv == OGS_OK);
if (rsp->cause.presence) {
ogs_gtp_cause_t *cause = rsp->cause.data;
ogs_assert(cause);
cause_value = cause->value;
if (cause_value != OGS_GTP_CAUSE_REQUEST_ACCEPTED)
ogs_warn("GTP Failed [CAUSE:%d] - Ignored", cause_value);
}
2019-04-27 14:54:30 +00:00
ogs_debug(" MME_S11_TEID[%d] SGW_S11_TEID[%d]",
mme_ue->mme_s11_teid, mme_ue->sgw_s11_teid);
2019-06-19 09:04:57 +00:00
if (OGS_FSM_CHECK(&mme_ue->sm, emm_state_authentication)) {
if (mme_sess_count(mme_ue) == 1) /* Last Session */ {
mme_s6a_send_air(mme_ue, NULL);
2018-01-30 12:57:19 +00:00
}
2019-06-19 09:04:57 +00:00
} else if (OGS_FSM_CHECK(&mme_ue->sm, emm_state_de_registered)) {
if (mme_sess_count(mme_ue) == 1) /* Last Session */ {
nas_send_detach_accept(mme_ue);
2018-01-30 12:57:19 +00:00
}
2019-06-19 09:04:57 +00:00
} else if (OGS_FSM_CHECK(&mme_ue->sm, emm_state_registered)) {
mme_bearer_t *bearer = mme_default_bearer_in_sess(sess);
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(bearer);
2019-06-19 09:04:57 +00:00
if (OGS_FSM_CHECK(&bearer->sm, esm_state_pdn_will_disconnect)) {
2019-11-30 07:45:09 +00:00
nas_send_deactivate_bearer_context_request(bearer);
2018-01-30 12:57:19 +00:00
/*
2018-02-09 07:43:28 +00:00
* mme_sess_remove() should not be called here.
2018-01-30 12:57:19 +00:00
*
2018-02-09 07:43:28 +00:00
* Session will be removed if Deactivate bearer context
* accept is received */
CLEAR_SGW_S1U_PATH(sess);
2018-01-30 12:57:19 +00:00
return;
2019-06-25 01:55:00 +00:00
} else if (OGS_FSM_CHECK(&bearer->sm, esm_state_active) ||
/*
* MME sends InitialContextSetupRequest to eNB.
* eNB sends InitialContextSetupFailure to MME.
*
* In this case, ESM state is INACTIVE.
*
* So, if Delete-Session-Response is received,
* MME needs to send UEContextReleaseCommand to eNB.
*/
OGS_FSM_CHECK(&bearer->sm, esm_state_inactive)) {
2019-06-19 09:04:57 +00:00
if (mme_sess_count(mme_ue) == 1) /* Last Session */ {
2019-05-26 03:22:43 +00:00
enb_ue_t *enb_ue = NULL;
enb_ue = mme_ue->enb_ue;
2019-06-14 15:11:30 +00:00
if (enb_ue) {
s1ap_send_ue_context_release_command(enb_ue,
2019-06-14 15:11:30 +00:00
S1AP_Cause_PR_nas, S1AP_CauseNas_normal_release,
S1AP_UE_CTX_REL_UE_CONTEXT_REMOVE, 0);
} else
ogs_warn("ENB-S1 Context has already been removed");
2019-05-26 03:22:43 +00:00
}
2019-06-19 09:04:57 +00:00
} else
2019-04-27 14:54:30 +00:00
ogs_assert_if_reached();
2019-06-25 01:55:00 +00:00
2019-06-19 09:04:57 +00:00
} else if (OGS_FSM_CHECK(&mme_ue->sm, emm_state_initial_context_setup) ||
OGS_FSM_CHECK(&mme_ue->sm, emm_state_exception)) {
if (mme_sess_count(mme_ue) == 1) /* Last Session */ {
enb_ue_t *enb_ue = NULL;
enb_ue = mme_ue->enb_ue;
2019-06-14 15:11:30 +00:00
if (enb_ue) {
s1ap_send_ue_context_release_command(enb_ue,
2019-06-14 15:11:30 +00:00
S1AP_Cause_PR_nas, S1AP_CauseNas_normal_release,
S1AP_UE_CTX_REL_UE_CONTEXT_REMOVE, 0);
} else
ogs_warn("ENB-S1 Context has already been removed");
2018-01-30 12:57:19 +00:00
}
2019-06-19 09:04:57 +00:00
} else
2019-04-27 14:54:30 +00:00
ogs_assert_if_reached();
2018-01-30 12:57:19 +00:00
if (mme_sess_count(mme_ue) == 1) /* Last Session */
2018-02-02 12:09:37 +00:00
CLEAR_SESSION_CONTEXT(mme_ue);
2018-01-30 12:57:19 +00:00
mme_sess_remove(sess);
}
void mme_s11_handle_create_bearer_request(
2019-09-13 12:07:47 +00:00
ogs_gtp_xact_t *xact, mme_ue_t *mme_ue,
ogs_gtp_create_bearer_request_t *req)
{
2019-04-27 14:54:30 +00:00
int rv;
uint8_t cause_value = 0;
mme_bearer_t *bearer = NULL, *default_bearer = NULL;
mme_sess_t *sess = NULL;
2019-09-13 12:07:47 +00:00
ogs_gtp_f_teid_t *sgw_s1u_teid = NULL;
ogs_gtp_bearer_qos_t bearer_qos;
2017-08-31 05:03:00 +00:00
2019-04-27 14:54:30 +00:00
ogs_assert(xact);
ogs_assert(req);
2017-09-01 12:35:45 +00:00
2019-04-27 14:54:30 +00:00
ogs_debug("[MME] Create Bearer Response");
2017-08-31 05:03:00 +00:00
cause_value = OGS_GTP_CAUSE_REQUEST_ACCEPTED;
2019-06-19 09:04:57 +00:00
if (req->linked_eps_bearer_id.presence == 0) {
2019-04-27 14:54:30 +00:00
ogs_error("No Linked EBI");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
}
if (mme_ue && cause_value == OGS_GTP_CAUSE_REQUEST_ACCEPTED) {
sess = mme_sess_find_by_ebi(mme_ue, req->linked_eps_bearer_id.u8);
ogs_assert(sess);
bearer = mme_bearer_add(sess);
ogs_assert(bearer);
}
if (!bearer) {
ogs_warn("No Context");
cause_value = OGS_GTP_CAUSE_CONTEXT_NOT_FOUND;
}
2019-06-19 09:04:57 +00:00
if (req->bearer_contexts.presence == 0) {
2019-04-27 14:54:30 +00:00
ogs_error("No Bearer");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
}
2019-06-19 09:04:57 +00:00
if (req->bearer_contexts.eps_bearer_id.presence == 0) {
2019-04-27 14:54:30 +00:00
ogs_error("No EPS Bearer ID");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
}
2019-06-19 09:04:57 +00:00
if (req->bearer_contexts.s1_u_enodeb_f_teid.presence == 0) {
2019-04-27 14:54:30 +00:00
ogs_error("No GTP TEID");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
}
2019-06-19 09:04:57 +00:00
if (req->bearer_contexts.bearer_level_qos.presence == 0) {
2019-04-27 14:54:30 +00:00
ogs_error("No QoS");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
}
2019-06-19 09:04:57 +00:00
if (req->bearer_contexts.tft.presence == 0) {
2019-04-27 14:54:30 +00:00
ogs_error("No TFT");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
}
if (cause_value != OGS_GTP_CAUSE_REQUEST_ACCEPTED) {
ogs_gtp_send_error_message(xact, mme_ue ? mme_ue->sgw_s11_teid : 0,
OGS_GTP_CREATE_BEARER_RESPONSE_TYPE, cause_value);
2017-09-06 06:38:24 +00:00
return;
}
2019-04-27 14:54:30 +00:00
ogs_debug(" MME_S11_TEID[%d] SGW_S11_TEID[%d]",
2018-01-22 15:00:57 +00:00
mme_ue->mme_s11_teid, mme_ue->sgw_s11_teid);
/* Data Plane(UL) : SGW-S1U */
sgw_s1u_teid = req->bearer_contexts.s1_u_enodeb_f_teid.data;
bearer->sgw_s1u_teid = ntohl(sgw_s1u_teid->teid);
2019-09-13 12:07:47 +00:00
rv = ogs_gtp_f_teid_to_ip(sgw_s1u_teid, &bearer->sgw_s1u_ip);
2019-04-27 14:54:30 +00:00
ogs_assert(rv == OGS_OK);
/* Bearer QoS */
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(ogs_gtp_parse_bearer_qos(&bearer_qos,
&req->bearer_contexts.bearer_level_qos) ==
2019-04-27 14:54:30 +00:00
req->bearer_contexts.bearer_level_qos.len);
bearer->qos.qci = bearer_qos.qci;
bearer->qos.arp.priority_level = bearer_qos.priority_level;
bearer->qos.arp.pre_emption_capability =
bearer_qos.pre_emption_capability;
bearer->qos.arp.pre_emption_vulnerability =
bearer_qos.pre_emption_vulnerability;
2017-09-04 15:04:05 +00:00
bearer->qos.mbr.downlink = bearer_qos.dl_mbr;
bearer->qos.mbr.uplink = bearer_qos.ul_mbr;
bearer->qos.gbr.downlink = bearer_qos.dl_gbr;
bearer->qos.gbr.uplink = bearer_qos.ul_gbr;
2017-09-06 15:37:16 +00:00
/* Save Bearer TFT */
2019-09-13 12:07:47 +00:00
OGS_TLV_STORE_DATA(&bearer->tft, &req->bearer_contexts.tft);
2017-09-06 06:38:24 +00:00
2017-09-06 15:37:16 +00:00
/* Save Transaction. will be handled after EMM-attached */
bearer->xact = xact;
/* Before Activate DEDICATED bearer, we'll check DEFAULT bearer status */
default_bearer = mme_default_bearer_in_sess(sess);
ogs_expect_or_return(default_bearer);
if (/* Check if Activate Default Bearer Accept is received */
2019-04-27 14:54:30 +00:00
OGS_FSM_CHECK(&default_bearer->sm, esm_state_active) &&
/* Check if Initial Context Setup Response or
* E-RAB Setup Response is received */
2019-06-19 09:04:57 +00:00
MME_HAVE_ENB_S1U_PATH(default_bearer)) {
2019-11-30 07:45:09 +00:00
nas_send_activate_dedicated_bearer_context_request(bearer);
}
}
void mme_s11_handle_update_bearer_request(
2019-09-13 12:07:47 +00:00
ogs_gtp_xact_t *xact, mme_ue_t *mme_ue,
ogs_gtp_update_bearer_request_t *req)
{
uint8_t cause_value = 0;
mme_bearer_t *bearer = NULL;
2019-09-13 12:07:47 +00:00
ogs_gtp_bearer_qos_t bearer_qos;
2019-04-27 14:54:30 +00:00
ogs_assert(xact);
ogs_assert(req);
2019-04-27 14:54:30 +00:00
ogs_debug("[MME] Update Bearer Request");
cause_value = OGS_GTP_CAUSE_REQUEST_ACCEPTED;
2019-06-19 09:04:57 +00:00
if (req->bearer_contexts.presence == 0) {
2019-04-27 14:54:30 +00:00
ogs_error("No Bearer");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
}
2019-06-19 09:04:57 +00:00
if (req->bearer_contexts.eps_bearer_id.presence == 0) {
2019-04-27 14:54:30 +00:00
ogs_error("No EPS Bearer ID");
cause_value = OGS_GTP_CAUSE_MANDATORY_IE_MISSING;
}
if (mme_ue && cause_value == OGS_GTP_CAUSE_REQUEST_ACCEPTED) {
bearer = mme_bearer_find_by_ue_ebi(mme_ue,
req->bearer_contexts.eps_bearer_id.u8);
ogs_expect_or_return(bearer);
}
if (!bearer) {
ogs_warn("No Context");
cause_value = OGS_GTP_CAUSE_CONTEXT_NOT_FOUND;
}
if (cause_value != OGS_GTP_CAUSE_REQUEST_ACCEPTED) {
ogs_gtp_send_error_message(xact, mme_ue ? mme_ue->sgw_s11_teid : 0,
OGS_GTP_UPDATE_BEARER_RESPONSE_TYPE, cause_value);
return;
}
2019-04-27 14:54:30 +00:00
ogs_debug(" MME_S11_TEID[%d] SGW_S11_TEID[%d]",
2018-01-22 15:00:57 +00:00
mme_ue->mme_s11_teid, mme_ue->sgw_s11_teid);
/* Save Transaction. will be handled after EMM-attached */
bearer->xact = xact;
if (/* Check if Activate Default/Dedicated Bearer Accept is received */
2019-04-27 14:54:30 +00:00
OGS_FSM_CHECK(&bearer->sm, esm_state_active) &&
/* Check if Initial Context Setup Response or
* E-RAB Setup Response is received */
2019-06-19 09:04:57 +00:00
MME_HAVE_ENB_S1U_PATH(bearer)) {
if (req->bearer_contexts.bearer_level_qos.presence == 1) {
/* Bearer QoS */
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(ogs_gtp_parse_bearer_qos(&bearer_qos,
&req->bearer_contexts.bearer_level_qos) ==
2019-04-27 14:54:30 +00:00
req->bearer_contexts.bearer_level_qos.len);
bearer->qos.qci = bearer_qos.qci;
bearer->qos.arp.priority_level = bearer_qos.priority_level;
bearer->qos.arp.pre_emption_capability =
bearer_qos.pre_emption_capability;
bearer->qos.arp.pre_emption_vulnerability =
bearer_qos.pre_emption_vulnerability;
bearer->qos.mbr.downlink = bearer_qos.dl_mbr;
bearer->qos.mbr.uplink = bearer_qos.ul_mbr;
bearer->qos.gbr.downlink = bearer_qos.dl_gbr;
bearer->qos.gbr.uplink = bearer_qos.ul_gbr;
}
2019-06-19 09:04:57 +00:00
if (req->bearer_contexts.tft.presence == 1) {
/* Save Bearer TFT */
2019-09-13 12:07:47 +00:00
OGS_TLV_STORE_DATA(&bearer->tft, &req->bearer_contexts.tft);
}
if (req->bearer_contexts.bearer_level_qos.presence == 1 ||
2019-06-19 09:04:57 +00:00
req->bearer_contexts.tft.presence == 1) {
2019-11-30 07:45:09 +00:00
nas_send_modify_bearer_context_request(bearer,
req->bearer_contexts.bearer_level_qos.presence,
req->bearer_contexts.tft.presence);
2019-06-19 09:04:57 +00:00
} else {
2019-04-27 14:54:30 +00:00
ogs_warn("[IGNORE] Update Bearer Request : "
"Both QoS and TFT is NULL");
if (xact->xid & OGS_GTP_CMD_XACT_ID) {
/* MME recieved Bearer resource modification request */
nas_send_bearer_resource_modification_reject(
bearer, ESM_CAUSE_SERVICE_OPTION_NOT_SUPPORTED);
}
2019-11-30 07:45:09 +00:00
mme_gtp_send_update_bearer_response(bearer);
}
2019-06-19 09:04:57 +00:00
} else {
if (!OGS_FSM_CHECK(&bearer->sm, esm_state_active)) {
2019-04-27 14:54:30 +00:00
ogs_assert_if_reached();
2019-06-19 09:04:57 +00:00
} else if (!MME_HAVE_ENB_S1U_PATH(bearer)) {
2019-04-27 14:54:30 +00:00
ogs_assert_if_reached();
2019-06-19 09:04:57 +00:00
} else
2019-04-27 14:54:30 +00:00
ogs_assert_if_reached();
}
}
void mme_s11_handle_delete_bearer_request(
2019-09-13 12:07:47 +00:00
ogs_gtp_xact_t *xact, mme_ue_t *mme_ue,
ogs_gtp_delete_bearer_request_t *req)
{
mme_bearer_t *bearer = NULL;
2019-04-27 14:54:30 +00:00
ogs_assert(xact);
ogs_assert(req);
2019-04-27 14:54:30 +00:00
ogs_debug("[MME] Delete Bearer Request");
if (mme_ue && req->linked_eps_bearer_id.presence == 1) {
2019-06-19 09:04:57 +00:00
bearer = mme_bearer_find_by_ue_ebi(
mme_ue, req->linked_eps_bearer_id.u8);
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(bearer);
} else if (mme_ue && req->eps_bearer_ids.presence == 1) {
bearer = mme_bearer_find_by_ue_ebi(
mme_ue, req->eps_bearer_ids.u8);
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(bearer);
2019-06-19 09:04:57 +00:00
} else {
2019-04-27 14:54:30 +00:00
ogs_error("No Linked EBI or EPS Bearer ID");
ogs_gtp_send_error_message(xact, mme_ue ? mme_ue->sgw_s11_teid : 0,
OGS_GTP_DELETE_BEARER_RESPONSE_TYPE,
OGS_GTP_CAUSE_CONTEXT_NOT_FOUND);
return;
}
ogs_assert(mme_ue);
2019-04-27 14:54:30 +00:00
ogs_debug(" MME_S11_TEID[%d] SGW_S11_TEID[%d]",
2018-01-22 15:00:57 +00:00
mme_ue->mme_s11_teid, mme_ue->sgw_s11_teid);
/* Save Transaction. will be handled after EMM-attached */
2019-11-30 07:45:09 +00:00
ogs_assert(bearer);
bearer->xact = xact;
if (/* Check if Activate Default/Dedicated Bearer Accept is received */
2019-04-27 14:54:30 +00:00
OGS_FSM_CHECK(&bearer->sm, esm_state_active) &&
/* Check if Initial Context Setup Response or
* E-RAB Setup Response is received */
2019-06-19 09:04:57 +00:00
MME_HAVE_ENB_S1U_PATH(bearer)) {
2019-11-30 07:45:09 +00:00
nas_send_deactivate_bearer_context_request(bearer);
2019-06-19 09:04:57 +00:00
} else {
if (!OGS_FSM_CHECK(&bearer->sm, esm_state_active)) {
2019-04-27 14:54:30 +00:00
ogs_assert_if_reached();
2019-06-19 09:04:57 +00:00
} else if (!MME_HAVE_ENB_S1U_PATH(bearer)) {
2019-04-27 14:54:30 +00:00
ogs_assert_if_reached();
2019-06-19 09:04:57 +00:00
} else
2019-04-27 14:54:30 +00:00
ogs_assert_if_reached();
}
}
void mme_s11_handle_release_access_bearers_response(
2019-09-13 12:07:47 +00:00
ogs_gtp_xact_t *xact, mme_ue_t *mme_ue,
ogs_gtp_release_access_bearers_response_t *rsp)
{
2019-04-27 14:54:30 +00:00
int rv;
uint8_t cause_value = 0;
enb_ue_t *enb_ue = NULL;
2017-09-01 12:35:45 +00:00
2019-04-27 14:54:30 +00:00
ogs_assert(xact);
ogs_assert(rsp);
2019-04-27 14:54:30 +00:00
ogs_debug("[MME] Release Access Bearers Response");
if (!mme_ue) {
ogs_warn("No Context in TEID");
mme_ue = xact->data;
ogs_assert(mme_ue);
}
2019-09-13 12:07:47 +00:00
rv = ogs_gtp_xact_commit(xact);
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(rv == OGS_OK);
if (rsp->cause.presence) {
ogs_gtp_cause_t *cause = rsp->cause.data;
ogs_assert(cause);
cause_value = cause->value;
if (cause_value != OGS_GTP_CAUSE_REQUEST_ACCEPTED)
ogs_warn("GTP Failed [CAUSE:%d]", cause_value);
}
ogs_debug(" MME_S11_TEID[%d] SGW_S11_TEID[%d]",
mme_ue->mme_s11_teid, mme_ue->sgw_s11_teid);
2017-08-31 05:03:00 +00:00
if (cause_value != OGS_GTP_CAUSE_REQUEST_ACCEPTED) {
mme_send_delete_session_or_mme_ue_context_release(mme_ue);
return;
}
rv = CLEAR_BEARER_CONTEXT(mme_ue);
ogs_expect(rv == OGS_OK);
enb_ue = mme_ue->enb_ue;
2019-06-14 15:11:30 +00:00
if (enb_ue) {
s1ap_send_ue_context_release_command(enb_ue,
2019-06-14 15:11:30 +00:00
S1AP_Cause_PR_nas, S1AP_CauseNas_normal_release,
S1AP_UE_CTX_REL_S1_REMOVE_AND_UNLINK, 0);
} else {
2019-06-14 15:11:30 +00:00
ogs_warn("ENB-S1 Context has already been removed");
}
}
void mme_s11_handle_downlink_data_notification(
2019-09-13 12:07:47 +00:00
ogs_gtp_xact_t *xact, mme_ue_t *mme_ue,
ogs_gtp_downlink_data_notification_t *noti)
{
2019-04-27 14:54:30 +00:00
int rv;
ogs_gtp_cause_t cause;
2019-09-13 12:07:47 +00:00
ogs_gtp_header_t h;
2019-04-27 14:54:30 +00:00
ogs_pkbuf_t *s11buf = NULL;
2019-04-27 14:54:30 +00:00
ogs_assert(xact);
ogs_assert(noti);
2019-04-27 14:54:30 +00:00
ogs_debug("[MME] Downlink Data Notification");
memset(&cause, 0, sizeof(cause));
cause.value = OGS_GTP_CAUSE_REQUEST_ACCEPTED;
if (!mme_ue) {
ogs_warn("No Context");
cause.value = OGS_GTP_CAUSE_CONTEXT_NOT_FOUND;
}
if (cause.value != OGS_GTP_CAUSE_REQUEST_ACCEPTED) {
ogs_gtp_send_error_message(xact, mme_ue ? mme_ue->sgw_s11_teid : 0,
OGS_GTP_DOWNLINK_DATA_NOTIFICATION_ACKNOWLEDGE_TYPE,
cause.value);
return;
}
2019-04-27 14:54:30 +00:00
ogs_debug(" MME_S11_TEID[%d] SGW_S11_TEID[%d]",
2018-01-11 04:42:33 +00:00
mme_ue->mme_s11_teid, mme_ue->sgw_s11_teid);
2017-08-09 15:41:09 +00:00
/* Build Downlink data notification ack */
2019-09-13 12:07:47 +00:00
memset(&h, 0, sizeof(ogs_gtp_header_t));
h.type = OGS_GTP_DOWNLINK_DATA_NOTIFICATION_ACKNOWLEDGE_TYPE;
2017-09-01 12:35:45 +00:00
h.teid = mme_ue->sgw_s11_teid;
2017-09-01 04:51:31 +00:00
2019-11-30 07:45:09 +00:00
s11buf = mme_s11_build_downlink_data_notification_ack(h.type);
ogs_expect_or_return(s11buf);
2017-08-09 15:41:09 +00:00
2019-09-13 12:07:47 +00:00
rv = ogs_gtp_xact_update_tx(xact, &h, s11buf);
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(rv == OGS_OK);
2017-08-31 05:03:00 +00:00
2019-09-13 12:07:47 +00:00
rv = ogs_gtp_xact_commit(xact);
ogs_expect(rv == OGS_OK);
}
void mme_s11_handle_create_indirect_data_forwarding_tunnel_response(
2019-09-13 12:07:47 +00:00
ogs_gtp_xact_t *xact, mme_ue_t *mme_ue,
ogs_gtp_create_indirect_data_forwarding_tunnel_response_t *rsp)
{
2019-04-27 14:54:30 +00:00
int rv;
uint8_t cause_value = 0;
2017-09-13 12:51:02 +00:00
mme_bearer_t *bearer = NULL;
2017-09-15 03:06:26 +00:00
enb_ue_t *source_ue = NULL;
2017-09-13 12:51:02 +00:00
int i;
2019-12-07 04:17:00 +00:00
ogs_gtp_tlv_bearer_context_t *bearers[OGS_GTP_MAX_INDIRECT_TUNNEL];
2019-09-13 12:07:47 +00:00
ogs_gtp_f_teid_t *teid = NULL;
2017-09-13 12:51:02 +00:00
2019-04-27 14:54:30 +00:00
ogs_assert(xact);
ogs_assert(rsp);
2017-09-13 12:51:02 +00:00
2019-04-27 14:54:30 +00:00
ogs_debug("[MME] Create Indirect Data Forwarding Tunnel Response");
if (!mme_ue) {
ogs_warn("No Context in TEID");
mme_ue = xact->data;
ogs_assert(mme_ue);
}
rv = ogs_gtp_xact_commit(xact);
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(rv == OGS_OK);
if (rsp->cause.presence) {
ogs_gtp_cause_t *cause = rsp->cause.data;
ogs_assert(cause);
cause_value = cause->value;
if (cause_value != OGS_GTP_CAUSE_REQUEST_ACCEPTED)
ogs_warn("GTP Failed [CAUSE:%d]", cause_value);
}
2019-04-27 14:54:30 +00:00
ogs_debug(" MME_S11_TEID[%d] SGW_S11_TEID[%d]",
2018-01-11 04:42:33 +00:00
mme_ue->mme_s11_teid, mme_ue->sgw_s11_teid);
2017-09-13 12:51:02 +00:00
if (cause_value != OGS_GTP_CAUSE_REQUEST_ACCEPTED) {
mme_send_delete_session_or_mme_ue_context_release(mme_ue);
return;
}
2019-09-13 12:07:47 +00:00
ogs_gtp_bearers_in_create_indirect_tunnel_response(&bearers, rsp);
2017-09-13 12:51:02 +00:00
2019-06-19 09:04:57 +00:00
for (i = 0; bearers[i]->presence; i++) {
if (bearers[i]->eps_bearer_id.presence == 0) {
2019-04-27 14:54:30 +00:00
ogs_error("No EBI");
2017-09-13 12:51:02 +00:00
return;
}
bearer = mme_bearer_find_by_ue_ebi(mme_ue,
bearers[i]->eps_bearer_id.u8);
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(bearer);
2017-09-13 12:51:02 +00:00
2019-06-19 09:04:57 +00:00
if (bearers[i]->s4_u_sgsn_f_teid.presence) {
2017-09-13 12:51:02 +00:00
teid = bearers[i]->s4_u_sgsn_f_teid.data;
2019-04-27 14:54:30 +00:00
ogs_assert(teid);
2017-09-13 12:51:02 +00:00
bearer->sgw_dl_teid = ntohl(teid->teid);
2019-09-13 12:07:47 +00:00
rv = ogs_gtp_f_teid_to_ip(teid, &bearer->sgw_dl_ip);
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(rv == OGS_OK);
2017-09-13 12:51:02 +00:00
}
2019-06-19 09:04:57 +00:00
if (bearers[i]->s2b_u_epdg_f_teid_5.presence) {
2017-09-13 12:51:02 +00:00
teid = bearers[i]->s2b_u_epdg_f_teid_5.data;
2019-04-27 14:54:30 +00:00
ogs_assert(teid);
2017-09-13 12:51:02 +00:00
bearer->sgw_ul_teid = ntohl(teid->teid);
2019-09-13 12:07:47 +00:00
rv = ogs_gtp_f_teid_to_ip(teid, &bearer->sgw_ul_ip);
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(rv == OGS_OK);
2017-09-13 12:51:02 +00:00
}
}
source_ue = mme_ue->enb_ue;
ogs_assert(source_ue);
2019-11-30 07:45:09 +00:00
s1ap_send_handover_command(source_ue);
}
2017-09-14 05:18:47 +00:00
void mme_s11_handle_delete_indirect_data_forwarding_tunnel_response(
2019-09-13 12:07:47 +00:00
ogs_gtp_xact_t *xact, mme_ue_t *mme_ue,
ogs_gtp_delete_indirect_data_forwarding_tunnel_response_t *rsp)
2017-09-14 05:18:47 +00:00
{
2019-04-27 14:54:30 +00:00
int rv;
uint8_t cause_value = 0;
2017-09-14 05:18:47 +00:00
2019-04-27 14:54:30 +00:00
ogs_assert(xact);
ogs_assert(rsp);
2017-09-14 05:18:47 +00:00
2019-04-27 14:54:30 +00:00
ogs_debug("[MME] Delete Indirect Data Forwarding Tunnel Response");
if (!mme_ue) {
ogs_warn("No Context in TEID");
mme_ue = xact->data;
ogs_assert(mme_ue);
}
rv = ogs_gtp_xact_commit(xact);
2019-11-30 07:45:09 +00:00
ogs_expect_or_return(rv == OGS_OK);
if (rsp->cause.presence) {
ogs_gtp_cause_t *cause = rsp->cause.data;
ogs_assert(cause);
cause_value = cause->value;
if (cause_value != OGS_GTP_CAUSE_REQUEST_ACCEPTED)
ogs_warn("GTP Failed [CAUSE:%d]", cause_value);
}
if (cause_value != OGS_GTP_CAUSE_REQUEST_ACCEPTED) {
mme_send_delete_session_or_mme_ue_context_release(mme_ue);
return;
}
2019-04-27 14:54:30 +00:00
ogs_debug(" MME_S11_TEID[%d] SGW_S11_TEID[%d]",
2018-01-11 04:42:33 +00:00
mme_ue->mme_s11_teid, mme_ue->sgw_s11_teid);
2017-09-14 05:18:47 +00:00
rv = mme_ue_clear_indirect_tunnel(mme_ue);
ogs_expect(rv == OGS_OK);
2017-09-14 05:18:47 +00:00
}
void mme_s11_handle_bearer_resource_failure_indication(
ogs_gtp_xact_t *xact, mme_ue_t *mme_ue,
ogs_gtp_bearer_resource_failure_indication_t *ind)
{
int rv;
uint8_t cause_value = 0;
mme_bearer_t *bearer = NULL;
ogs_assert(xact);
bearer = xact->data;
ogs_assert(ind);
ogs_debug("[MME] Bearer Resource Failure Indication");
rv = ogs_gtp_xact_commit(xact);
ogs_expect_or_return(rv == OGS_OK);
if (ind->cause.presence) {
ogs_gtp_cause_t *cause = ind->cause.data;
ogs_assert(cause);
cause_value = cause->value;
if (cause_value != OGS_GTP_CAUSE_REQUEST_ACCEPTED)
ogs_warn("GTP Failed [CAUSE:%d] - Ignored", cause_value);
} else {
ogs_error("No Cause");
}
ogs_debug(" MME_S11_TEID[%d] SGW_S11_TEID[%d]",
mme_ue->mme_s11_teid, mme_ue->sgw_s11_teid);
nas_send_bearer_resource_modification_reject(
bearer, ESM_CAUSE_SERVICE_OPTION_NOT_SUPPORTED);
}