open5gs/src/mme/esm-handler.c

194 lines
5.9 KiB
C
Raw Normal View History

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"
#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"
#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
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
memcpy(&sess->request_type, &req->request_type, sizeof(sess->request_type));
2017-12-14 12:42:19 +00:00
security_protected_required = 0;
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 =
&req->esm_information_transfer_flag;
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);
}
if (req->presencemask &
2020-05-23 02:24:48 +00:00
OGS_NAS_EPS_PDN_CONNECTIVITY_REQUEST_ACCESS_POINT_NAME_PRESENT) {
sess->pdn = mme_pdn_find_by_apn(mme_ue, req->access_point_name.apn);
2019-06-23 11:43:23 +00:00
if (!sess->pdn) {
2017-12-19 08:05:54 +00:00
/* Invalid APN */
2020-05-23 02:24:48 +00:00
nas_eps_send_pdn_connectivity_reject(
2017-12-19 08:05:54 +00:00
sess, ESM_CAUSE_MISSING_OR_UNKNOWN_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
}
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 =
&req->protocol_configuration_options;
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);
2020-05-23 02:24:48 +00:00
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
}
2019-06-23 11:43:23 +00:00
if (!sess->pdn) {
2017-12-19 08:05:54 +00:00
/* Default APN */
sess->pdn = mme_default_pdn(mme_ue);
}
2019-06-23 11:43:23 +00:00
if (sess->pdn) {
2019-04-27 14:54:30 +00:00
ogs_debug(" APN[%s]", sess->pdn->apn);
2019-11-30 07:45:09 +00:00
mme_gtp_send_create_session_request(sess);
2019-06-23 11:43:23 +00:00
} else {
2020-05-23 02:24:48 +00:00
nas_eps_send_pdn_connectivity_reject(
2017-12-19 08:05:54 +00:00
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
}
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
{
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);
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
ogs_assert(rsp);
if (rsp->presencemask &
2020-05-23 02:24:48 +00:00
OGS_NAS_EPS_ESM_INFORMATION_RESPONSE_ACCESS_POINT_NAME_PRESENT) {
sess->pdn = mme_pdn_find_by_apn(mme_ue, rsp->access_point_name.apn);
2017-04-11 12:38:24 +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 =
&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
2019-06-23 11:43:23 +00:00
if (sess->pdn) {
2019-04-27 14:54:30 +00:00
ogs_debug(" APN[%s]", sess->pdn->apn);
2019-06-23 11:43:23 +00:00
if (SESSION_CONTEXT_IS_AVAILABLE(mme_ue)) {
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) {
sgsap_send_location_update_request(mme_ue);
2019-07-20 13:30:53 +00:00
} else {
if (sess->pdn->paa.pdn_type == OGS_GTP_PDN_TYPE_IPV4) {
/* Nothing */
} else if (sess->pdn->paa.pdn_type == OGS_GTP_PDN_TYPE_IPV6) {
/* Nothing */
} else if (sess->pdn->paa.pdn_type == OGS_GTP_PDN_TYPE_IPV4V6) {
/* Nothing */
} else {
ogs_error("Unknown PDN[%s] Type %u:%u",
sess->pdn->apn,
sess->pdn->pdn_type,
sess->pdn->paa.pdn_type);
nas_eps_send_pdn_connectivity_reject(
sess, ESM_CAUSE_UNKNOWN_PDN_TYPE);
return OGS_ERROR;
}
2020-05-23 02:24:48 +00:00
nas_eps_send_attach_accept(mme_ue);
2019-07-20 13:30:53 +00:00
}
2019-06-23 11:43:23 +00:00
} else {
2019-11-30 07:45:09 +00:00
mme_gtp_send_create_session_request(sess);
}
2019-06-23 11:43:23 +00:00
} else {
2020-05-23 02:24:48 +00:00
nas_eps_send_pdn_connectivity_reject(
sess, ESM_CAUSE_MISSING_OR_UNKNOWN_APN);
2019-04-27 14:54:30 +00:00
return OGS_ERROR;
}
2019-04-27 14:54:30 +00:00
return OGS_OK;
2017-04-11 06:07:46 +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)
{
ogs_assert(bearer);
2020-05-23 02:24:48 +00:00
nas_eps_send_bearer_resource_allocation_reject(
bearer, ESM_CAUSE_SERVICE_OPTION_NOT_SUPPORTED);
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)
{
mme_ue_t *mme_ue = NULL;
ogs_assert(bearer);
mme_ue = bearer->mme_ue;
ogs_assert(mme_ue);
mme_gtp_send_bearer_resource_command(bearer, message);
return OGS_OK;
}