2019-06-23 11:43:23 +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-context.h"
|
|
|
|
#include "nas-path.h"
|
2019-06-22 02:16:22 +00:00
|
|
|
#include "sgsap-path.h"
|
2019-06-11 13:10:47 +00:00
|
|
|
#include "mme-gtp-path.h"
|
2017-09-07 06:56:31 +00:00
|
|
|
|
2019-06-11 13:10:47 +00:00
|
|
|
#include "esm-build.h"
|
2019-10-27 08:41:14 +00:00
|
|
|
#include "esm-handler.h"
|
2017-04-08 02:38:09 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
#undef OGS_LOG_DOMAIN
|
|
|
|
#define OGS_LOG_DOMAIN __esm_log_domain
|
|
|
|
|
|
|
|
int esm_handle_pdn_connectivity_request(mme_bearer_t *bearer,
|
2020-05-23 02:24:48 +00:00
|
|
|
ogs_nas_eps_pdn_connectivity_request_t *req)
|
2017-04-08 02:38:09 +00:00
|
|
|
{
|
2017-09-06 15:37:16 +00:00
|
|
|
mme_ue_t *mme_ue = NULL;
|
2017-09-08 07:46:37 +00:00
|
|
|
mme_sess_t *sess = NULL;
|
2019-04-27 14:54:30 +00:00
|
|
|
uint8_t security_protected_required = 0;
|
2017-09-06 15:37:16 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(bearer);
|
2017-09-08 07:46:37 +00:00
|
|
|
sess = bearer->sess;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(sess);
|
2017-09-06 15:37:16 +00:00
|
|
|
mme_ue = sess->mme_ue;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(mme_ue);
|
2017-12-14 12:42:19 +00:00
|
|
|
|
2019-12-28 12:46:30 +00:00
|
|
|
ogs_assert(req);
|
2017-09-06 15:37:16 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(MME_UE_HAVE_IMSI(mme_ue));
|
|
|
|
ogs_assert(SECURITY_CONTEXT_IS_VALID(mme_ue));
|
2017-09-08 07:46:37 +00:00
|
|
|
|
2019-12-28 12:46:30 +00:00
|
|
|
memcpy(&sess->request_type, &req->request_type, sizeof(sess->request_type));
|
2017-12-14 12:42:19 +00:00
|
|
|
|
2017-09-23 15:59:51 +00:00
|
|
|
security_protected_required = 0;
|
2019-12-28 12:46:30 +00:00
|
|
|
if (req->presencemask &
|
2020-05-23 02:24:48 +00:00
|
|
|
OGS_NAS_EPS_PDN_CONNECTIVITY_REQUEST_ESM_INFORMATION_TRANSFER_FLAG_PRESENT) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_nas_esm_information_transfer_flag_t *esm_information_transfer_flag =
|
2019-12-28 12:46:30 +00:00
|
|
|
&req->esm_information_transfer_flag;
|
2017-09-23 15:59:51 +00:00
|
|
|
security_protected_required =
|
|
|
|
esm_information_transfer_flag->security_protected_required;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_debug(" EIT(ESM information transfer)[%d]",
|
2018-01-22 14:14:20 +00:00
|
|
|
security_protected_required);
|
2017-09-23 15:59:51 +00:00
|
|
|
}
|
|
|
|
|
2019-12-28 12:46:30 +00:00
|
|
|
if (req->presencemask &
|
2020-05-23 02:24:48 +00:00
|
|
|
OGS_NAS_EPS_PDN_CONNECTIVITY_REQUEST_ACCESS_POINT_NAME_PRESENT) {
|
2021-03-08 12:25:09 +00:00
|
|
|
sess->session = mme_session_find_by_apn(
|
|
|
|
mme_ue, req->access_point_name.apn);
|
|
|
|
if (!sess->session) {
|
2017-12-19 08:05:54 +00:00
|
|
|
/* Invalid APN */
|
2021-05-16 03:22:10 +00:00
|
|
|
ogs_assert(OGS_OK ==
|
|
|
|
nas_eps_send_pdn_connectivity_reject(
|
|
|
|
sess, ESM_CAUSE_MISSING_OR_UNKNOWN_APN));
|
2021-11-30 07:01:37 +00:00
|
|
|
ogs_warn("Invalid APN[%s]", req->access_point_name.apn);
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_ERROR;
|
2017-12-19 08:05:54 +00:00
|
|
|
}
|
2017-09-06 15:37:16 +00:00
|
|
|
}
|
2017-08-26 09:52:06 +00:00
|
|
|
|
2019-12-28 12:46:30 +00:00
|
|
|
if (req->presencemask &
|
2020-05-23 02:24:48 +00:00
|
|
|
OGS_NAS_EPS_PDN_CONNECTIVITY_REQUEST_PROTOCOL_CONFIGURATION_OPTIONS_PRESENT) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_nas_protocol_configuration_options_t
|
|
|
|
*protocol_configuration_options =
|
2019-12-28 12:46:30 +00:00
|
|
|
&req->protocol_configuration_options;
|
2017-09-06 11:29:55 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
OGS_NAS_STORE_DATA(&sess->ue_pco, protocol_configuration_options);
|
2017-04-14 02:51:27 +00:00
|
|
|
}
|
2017-09-08 07:46:37 +00:00
|
|
|
|
2019-06-23 11:43:23 +00:00
|
|
|
if (security_protected_required) {
|
2019-07-20 14:06:54 +00:00
|
|
|
CLEAR_BEARER_TIMER(bearer->t3489);
|
2021-08-08 03:38:15 +00:00
|
|
|
ogs_assert(OGS_OK == nas_eps_send_esm_information_request(bearer));
|
2017-12-19 08:05:54 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2017-12-19 08:05:54 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 12:25:09 +00:00
|
|
|
if (!sess->session) {
|
2017-12-19 08:05:54 +00:00
|
|
|
/* Default APN */
|
2021-03-08 12:25:09 +00:00
|
|
|
sess->session = mme_default_session(mme_ue);
|
2017-12-19 08:05:54 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 12:25:09 +00:00
|
|
|
if (sess->session) {
|
2020-10-29 04:18:11 +00:00
|
|
|
mme_bearer_t *default_bearer = NULL;
|
|
|
|
mme_bearer_t *dedicated_bearer = NULL, *next_dedicated_bearer = NULL;
|
|
|
|
|
2021-03-08 12:25:09 +00:00
|
|
|
ogs_assert(sess->session->name);
|
|
|
|
ogs_debug(" APN[%s]", sess->session->name);
|
2020-10-29 04:18:11 +00:00
|
|
|
|
|
|
|
default_bearer = mme_default_bearer_in_sess(sess);
|
|
|
|
if (default_bearer) {
|
|
|
|
dedicated_bearer = mme_bearer_next(default_bearer);
|
|
|
|
while (dedicated_bearer) {
|
|
|
|
next_dedicated_bearer = mme_bearer_next(dedicated_bearer);
|
|
|
|
|
|
|
|
ogs_warn("Dedicated-Bearer[%d] removed forcely",
|
|
|
|
dedicated_bearer->ebi);
|
|
|
|
mme_bearer_remove(dedicated_bearer);
|
|
|
|
|
|
|
|
dedicated_bearer = next_dedicated_bearer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-16 03:22:10 +00:00
|
|
|
ogs_assert(OGS_OK ==
|
|
|
|
mme_gtp_send_create_session_request(sess));
|
2019-06-23 11:43:23 +00:00
|
|
|
} else {
|
2021-01-05 04:24:22 +00:00
|
|
|
ogs_error("No APN");
|
2021-05-16 03:22:10 +00:00
|
|
|
ogs_assert(OGS_OK ==
|
|
|
|
nas_eps_send_pdn_connectivity_reject(
|
|
|
|
sess, ESM_CAUSE_MISSING_OR_UNKNOWN_APN));
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_ERROR;
|
2017-09-08 07:46:37 +00:00
|
|
|
}
|
2017-09-23 15:59:51 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2017-04-08 02:38:09 +00:00
|
|
|
}
|
2017-04-11 06:07:46 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
int esm_handle_information_response(mme_sess_t *sess,
|
2020-05-23 02:24:48 +00:00
|
|
|
ogs_nas_eps_esm_information_response_t *rsp)
|
2017-04-11 06:07:46 +00:00
|
|
|
{
|
2017-04-28 07:11:45 +00:00
|
|
|
mme_ue_t *mme_ue = NULL;
|
2017-04-11 06:13:30 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(sess);
|
2017-08-26 09:52:06 +00:00
|
|
|
mme_ue = sess->mme_ue;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(mme_ue);
|
2017-04-12 04:45:57 +00:00
|
|
|
|
2019-12-28 12:46:30 +00:00
|
|
|
ogs_assert(rsp);
|
|
|
|
|
|
|
|
if (rsp->presencemask &
|
2020-05-23 02:24:48 +00:00
|
|
|
OGS_NAS_EPS_ESM_INFORMATION_RESPONSE_ACCESS_POINT_NAME_PRESENT) {
|
2021-03-08 12:25:09 +00:00
|
|
|
sess->session = mme_session_find_by_apn(
|
|
|
|
mme_ue, rsp->access_point_name.apn);
|
2017-04-11 12:38:24 +00:00
|
|
|
}
|
|
|
|
|
2019-12-28 12:46:30 +00:00
|
|
|
if (rsp->presencemask &
|
2020-05-23 02:24:48 +00:00
|
|
|
OGS_NAS_EPS_ESM_INFORMATION_RESPONSE_PROTOCOL_CONFIGURATION_OPTIONS_PRESENT) {
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_nas_protocol_configuration_options_t
|
|
|
|
*protocol_configuration_options =
|
2019-12-28 12:46:30 +00:00
|
|
|
&rsp->protocol_configuration_options;
|
2019-09-13 12:07:47 +00:00
|
|
|
OGS_NAS_STORE_DATA(&sess->ue_pco, protocol_configuration_options);
|
2017-04-11 14:25:33 +00:00
|
|
|
}
|
2017-09-08 07:46:37 +00:00
|
|
|
|
2021-03-08 12:25:09 +00:00
|
|
|
if (sess->session) {
|
|
|
|
ogs_assert(sess->session->name);
|
|
|
|
ogs_debug(" APN[%s]", sess->session->name);
|
2020-09-25 01:29:48 +00:00
|
|
|
|
2020-12-17 03:44:32 +00:00
|
|
|
if (SESSION_CONTEXT_IS_AVAILABLE(mme_ue) &&
|
2021-03-08 12:25:09 +00:00
|
|
|
OGS_PDU_SESSION_TYPE_IS_VALID(sess->session->paa.session_type)) {
|
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-06-22 02:16:22 +00:00
|
|
|
|
2019-07-21 11:25:29 +00:00
|
|
|
if (csmap) {
|
2021-05-16 03:22:10 +00:00
|
|
|
ogs_assert(OGS_OK ==
|
|
|
|
sgsap_send_location_update_request(mme_ue));
|
2019-07-20 13:30:53 +00:00
|
|
|
} else {
|
2021-05-16 03:22:10 +00:00
|
|
|
ogs_assert(OGS_OK ==
|
|
|
|
nas_eps_send_attach_accept(mme_ue));
|
2019-07-20 13:30:53 +00:00
|
|
|
}
|
2019-06-23 11:43:23 +00:00
|
|
|
} else {
|
2021-05-16 03:22:10 +00:00
|
|
|
ogs_assert(OGS_OK ==
|
|
|
|
mme_gtp_send_create_session_request(sess));
|
2017-09-23 15:59:51 +00:00
|
|
|
}
|
2019-06-23 11:43:23 +00:00
|
|
|
} else {
|
2021-11-30 07:01:37 +00:00
|
|
|
if (rsp->access_point_name.apn)
|
2021-11-30 06:52:20 +00:00
|
|
|
ogs_error("Invalid APN[%s]", rsp->access_point_name.apn);
|
|
|
|
else
|
|
|
|
ogs_error("No APN");
|
2021-05-16 03:22:10 +00:00
|
|
|
ogs_assert(OGS_OK ==
|
|
|
|
nas_eps_send_pdn_connectivity_reject(
|
|
|
|
sess, ESM_CAUSE_MISSING_OR_UNKNOWN_APN));
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_ERROR;
|
2017-09-23 15:59:51 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2017-04-11 06:07:46 +00:00
|
|
|
}
|
2019-12-28 12:46:30 +00:00
|
|
|
|
|
|
|
int esm_handle_bearer_resource_allocation_request(
|
2020-05-23 02:24:48 +00:00
|
|
|
mme_bearer_t *bearer, ogs_nas_eps_message_t *message)
|
2019-12-28 12:46:30 +00:00
|
|
|
{
|
2021-01-11 04:36:12 +00:00
|
|
|
mme_ue_t *mme_ue = NULL;
|
|
|
|
mme_sess_t *sess = NULL;
|
|
|
|
|
2019-12-28 12:46:30 +00:00
|
|
|
ogs_assert(bearer);
|
2021-01-11 04:36:12 +00:00
|
|
|
sess = bearer->sess;
|
|
|
|
ogs_assert(sess);
|
|
|
|
mme_ue = sess->mme_ue;
|
|
|
|
ogs_assert(mme_ue);
|
|
|
|
|
2021-05-16 03:22:10 +00:00
|
|
|
ogs_assert(OGS_OK ==
|
|
|
|
nas_eps_send_bearer_resource_allocation_reject(
|
|
|
|
mme_ue, sess->pti, ESM_CAUSE_NETWORK_FAILURE));
|
2019-12-28 12:46:30 +00:00
|
|
|
|
|
|
|
return OGS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int esm_handle_bearer_resource_modification_request(
|
2020-05-23 02:24:48 +00:00
|
|
|
mme_bearer_t *bearer, ogs_nas_eps_message_t *message)
|
2019-12-28 12:46:30 +00:00
|
|
|
{
|
|
|
|
mme_ue_t *mme_ue = NULL;
|
|
|
|
|
|
|
|
ogs_assert(bearer);
|
|
|
|
mme_ue = bearer->mme_ue;
|
|
|
|
ogs_assert(mme_ue);
|
|
|
|
|
2021-05-16 03:22:10 +00:00
|
|
|
ogs_assert(OGS_OK ==
|
|
|
|
mme_gtp_send_bearer_resource_command(bearer, message));
|
2019-12-28 12:46:30 +00:00
|
|
|
|
|
|
|
return OGS_OK;
|
|
|
|
}
|