open5gs/src/mme/esm-handler.c

163 lines
5.1 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 09:28:25 +00:00
#include "nas/nas-message.h"
2017-03-27 10:32:24 +00:00
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"
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,
2017-04-08 02:38:09 +00:00
nas_pdn_connectivity_request_t *pdn_connectivity_request)
{
2019-04-27 14:54:30 +00:00
int rv;
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-04-27 14:54:30 +00:00
ogs_assert(pdn_connectivity_request);
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
2017-12-14 12:42:19 +00:00
memcpy(&sess->request_type, &pdn_connectivity_request->request_type,
sizeof(sess->request_type));
security_protected_required = 0;
if (pdn_connectivity_request->presencemask &
2019-06-23 11:43:23 +00:00
NAS_PDN_CONNECTIVITY_REQUEST_ESM_INFORMATION_TRANSFER_FLAG_PRESENT) {
nas_esm_information_transfer_flag_t *esm_information_transfer_flag =
&pdn_connectivity_request->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);
}
2017-09-06 15:37:16 +00:00
if (pdn_connectivity_request->presencemask &
2019-06-23 11:43:23 +00:00
NAS_PDN_CONNECTIVITY_REQUEST_ACCESS_POINT_NAME_PRESENT) {
2017-09-06 15:37:16 +00:00
sess->pdn = mme_pdn_find_by_apn(mme_ue,
pdn_connectivity_request->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 */
rv = nas_send_pdn_connectivity_reject(
sess, ESM_CAUSE_MISSING_OR_UNKNOWN_APN);
2019-04-27 14:54:30 +00:00
ogs_assert(rv == OGS_OK);
2017-12-19 08:05:54 +00:00
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-04-14 02:51:27 +00:00
if (pdn_connectivity_request->presencemask &
2019-06-23 11:43:23 +00:00
NAS_PDN_CONNECTIVITY_REQUEST_PROTOCOL_CONFIGURATION_OPTIONS_PRESENT) {
2017-04-14 02:51:27 +00:00
nas_protocol_configuration_options_t *protocol_configuration_options =
&pdn_connectivity_request->protocol_configuration_options;
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);
nas_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);
2017-12-19 08:05:54 +00:00
rv = mme_gtp_send_create_session_request(sess);
2019-04-27 14:54:30 +00:00
ogs_assert(rv == OGS_OK);
2019-06-23 11:43:23 +00:00
} else {
2017-12-19 08:05:54 +00:00
rv = nas_send_pdn_connectivity_reject(
sess, ESM_CAUSE_MISSING_OR_UNKNOWN_APN);
2019-04-27 14:54:30 +00:00
ogs_assert(rv == OGS_OK);
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,
2017-04-11 06:07:46 +00:00
nas_esm_information_response_t *esm_information_response)
{
2019-04-27 14:54:30 +00:00
int rv;
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
2017-04-11 12:38:24 +00:00
if (esm_information_response->presencemask &
2019-06-23 11:43:23 +00:00
NAS_ESM_INFORMATION_RESPONSE_ACCESS_POINT_NAME_PRESENT) {
2017-08-11 11:25:52 +00:00
sess->pdn = mme_pdn_find_by_apn(mme_ue,
2017-04-11 12:38:24 +00:00
esm_information_response->access_point_name.apn);
}
2017-04-11 14:25:33 +00:00
if (esm_information_response->presencemask &
2019-06-23 11:43:23 +00:00
NAS_ESM_INFORMATION_RESPONSE_PROTOCOL_CONFIGURATION_OPTIONS_PRESENT) {
2017-04-11 14:25:33 +00:00
nas_protocol_configuration_options_t *protocol_configuration_options =
&esm_information_response->protocol_configuration_options;
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)) {
mme_vlr_t *vlr = mme_vlr_find_by_tai(&mme_ue->tai);
mme_ue->vlr = vlr;
2019-07-20 13:30:53 +00:00
if (vlr) {
sgsap_send_location_update_request(mme_ue);
2019-07-20 13:30:53 +00:00
} else {
CLEAR_MME_UE_TIMER(mme_ue->t3450);
nas_send_attach_accept(mme_ue);
2019-07-20 13:30:53 +00:00
}
2019-06-23 11:43:23 +00:00
} else {
rv = mme_gtp_send_create_session_request(sess);
2019-04-27 14:54:30 +00:00
ogs_assert(rv == OGS_OK);
}
2019-06-23 11:43:23 +00:00
} else {
rv = nas_send_pdn_connectivity_reject(
sess, ESM_CAUSE_MISSING_OR_UNKNOWN_APN);
2019-04-27 14:54:30 +00:00
ogs_assert(rv == OGS_OK);
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
}