open5gs/src/smf/ngap-handler.c

149 lines
5.0 KiB
C
Raw Normal View History

2020-06-17 05:22:28 +00:00
/*
* Copyright (C) 2019,2020 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/>.
*/
#include "ngap-handler.h"
#include "sbi-path.h"
#include "pfcp-path.h"
int ngap_handle_pdu_session_resource_setup_response_transfer(
2020-07-31 02:10:20 +00:00
smf_sess_t *sess, ogs_sbi_session_t *session, ogs_pkbuf_t *pkbuf)
2020-06-17 05:22:28 +00:00
{
smf_ue_t *smf_ue = NULL;
2020-07-20 01:42:58 +00:00
smf_bearer_t *qos_flow = NULL;
2020-06-17 05:22:28 +00:00
int rv, i;
2020-07-20 01:42:58 +00:00
uint32_t upf_n3_teid;
ogs_ip_t upf_n3_ip;
2020-06-22 03:07:14 +00:00
ogs_pfcp_far_t *dl_far = NULL;
2020-06-22 03:07:14 +00:00
bool far_update = false;
2020-06-17 05:22:28 +00:00
NGAP_PDUSessionResourceSetupResponseTransfer_t message;
NGAP_QosFlowPerTNLInformation_t *dLQosFlowPerTNLInformation = NULL;
NGAP_UPTransportLayerInformation_t *uPTransportLayerInformation = NULL;
NGAP_GTPTunnel_t *gTPTunnel = NULL;
NGAP_AssociatedQosFlowList_t *associatedQosFlowList = NULL;
ogs_assert(pkbuf);
ogs_assert(session);
2020-07-31 02:10:20 +00:00
ogs_assert(sess);
smf_ue = sess->smf_ue;
ogs_assert(smf_ue);
2020-06-17 05:22:28 +00:00
rv = ogs_asn_decode(
&asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer,
&message, sizeof(message), pkbuf);
if (rv != OGS_OK) {
ogs_error("[%s:%d] Cannot decode NGAP message",
smf_ue->supi, sess->psi);
2020-06-17 05:22:28 +00:00
smf_sbi_send_sm_context_update_error(session,
OGS_SBI_HTTP_STATUS_BAD_REQUEST,
2020-07-02 05:50:23 +00:00
"No N2 SM Info Type", smf_ue->supi, NULL, NULL);
2020-06-17 05:22:28 +00:00
goto cleanup;
}
rv = OGS_ERROR;
dLQosFlowPerTNLInformation = &message.dLQosFlowPerTNLInformation;
uPTransportLayerInformation =
&dLQosFlowPerTNLInformation->uPTransportLayerInformation;
if (uPTransportLayerInformation->present !=
NGAP_UPTransportLayerInformation_PR_gTPTunnel) {
ogs_error(
"[%s:%d] Unknown NGAP_UPTransportLayerInformation.present [%d]",
2020-06-22 03:07:14 +00:00
smf_ue->supi, sess->psi,
uPTransportLayerInformation->present);
2020-06-17 05:22:28 +00:00
smf_sbi_send_sm_context_update_error(session,
OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"Unknown NGAP_UPTransportLayerInformation.present",
2020-07-02 05:50:23 +00:00
smf_ue->supi, NULL, NULL);
2020-06-17 05:22:28 +00:00
goto cleanup;
}
associatedQosFlowList = &dLQosFlowPerTNLInformation->associatedQosFlowList;
for (i = 0; i < associatedQosFlowList->list.count; i++) {
NGAP_AssociatedQosFlowItem_t *associatedQosFlowItem = NULL;
associatedQosFlowItem = (NGAP_AssociatedQosFlowItem_t *)
associatedQosFlowList->list.array[i];
if (associatedQosFlowItem) {
2020-07-20 01:42:58 +00:00
qos_flow = smf_qos_flow_find_by_qfi(sess,
associatedQosFlowItem->qosFlowIdentifier);
2020-06-17 05:22:28 +00:00
}
}
2020-07-20 01:42:58 +00:00
if (!qos_flow) {
ogs_error("[%s:%d] No QoS flow", smf_ue->supi, sess->psi);
smf_sbi_send_sm_context_update_error(session,
OGS_SBI_HTTP_STATUS_BAD_REQUEST,
"No QoS flow", smf_ue->supi, NULL, NULL);
goto cleanup;
}
2020-06-17 05:22:28 +00:00
gTPTunnel = uPTransportLayerInformation->choice.gTPTunnel;
if (!gTPTunnel) {
ogs_error("[%s:%d] No GTPTunnel", smf_ue->supi, sess->psi);
2020-06-17 05:22:28 +00:00
smf_sbi_send_sm_context_update_error(session,
OGS_SBI_HTTP_STATUS_BAD_REQUEST,
2020-07-02 05:50:23 +00:00
"No GTPTunnel", smf_ue->supi, NULL, NULL);
2020-06-17 05:22:28 +00:00
goto cleanup;
}
ogs_asn_BIT_STRING_to_ip(
2020-07-20 01:42:58 +00:00
&gTPTunnel->transportLayerAddress, &upf_n3_ip);
ogs_asn_OCTET_STRING_to_uint32(&gTPTunnel->gTP_TEID, &upf_n3_teid);
2020-06-22 03:07:14 +00:00
/* Need to Update? */
2020-07-20 01:42:58 +00:00
if (memcmp(&sess->gnb_n3_ip, &upf_n3_ip, sizeof(sess->gnb_n3_ip)) != 0 ||
sess->gnb_n3_teid != upf_n3_teid)
far_update = true;
2020-06-22 03:07:14 +00:00
dl_far = qos_flow->dl_far;
ogs_assert(dl_far);
if (dl_far->apply_action != OGS_PFCP_APPLY_ACTION_FORW) {
far_update = true;
2020-06-22 03:07:14 +00:00
}
2020-07-20 01:42:58 +00:00
/* Setup FAR */
memcpy(&sess->gnb_n3_ip, &upf_n3_ip, sizeof(sess->gnb_n3_ip));
sess->gnb_n3_teid = upf_n3_teid;
ogs_pfcp_ip_to_outer_header_creation(&sess->gnb_n3_ip,
&dl_far->outer_header_creation, &dl_far->outer_header_creation_len);
dl_far->outer_header_creation.teid = sess->gnb_n3_teid;
2020-07-20 01:42:58 +00:00
if (far_update) {
smf_5gc_pfcp_send_qos_flow_modification_request(
2020-08-13 00:31:22 +00:00
qos_flow, session, OGS_PFCP_MODIFY_ACTIVATE);
} else {
/* ACTIVATED Is NOT Inlcuded in RESPONSE */
smf_sbi_send_sm_context_updated_data(sess, session, 0);
}
2020-06-17 05:22:28 +00:00
rv = OGS_OK;
cleanup:
ogs_asn_free(
&asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, &message);
return rv;
}