open5gs/src/amf/namf-build.c

101 lines
3.1 KiB
C

/*
* 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 "namf-build.h"
static char* ogs_guti_to_string(amf_ue_t *amf_ue)
{
ogs_plmn_id_t plmn_id;
char plmn_id_buff[OGS_PLMNIDSTRLEN];
char *amf_id = NULL;
char *tmsi = NULL;
char *guti = NULL;
memset(&plmn_id, 0, sizeof(plmn_id));
ogs_nas_to_plmn_id(&plmn_id, &amf_ue->current.guti.nas_plmn_id);
amf_id = ogs_amf_id_to_string(&amf_ue->current.guti.amf_id);
tmsi = ogs_uint32_to_0string(*(amf_ue->current.m_tmsi));
guti = ogs_msprintf("5g-guti-%s%s%s",
ogs_plmn_id_to_string(&plmn_id, plmn_id_buff),
amf_id,
tmsi);
/* TS29.518 6.1.3.2.2 Guti pattern (27 or 28 characters):
"5g-guti-[0-9]{5,6}[0-9a-fA-F]{14}" */
ogs_assert(strlen(guti) == (OGS_MAX_5G_GUTI_LEN - 1) ||
(strlen(guti)) == OGS_MAX_5G_GUTI_LEN);
ogs_free(amf_id);
ogs_free(tmsi);
return guti;
}
static char* amf_ue_to_context_id(amf_ue_t *amf_ue)
{
char *ue_context_id = NULL;
if (amf_ue->supi) {
ue_context_id = ogs_strdup(amf_ue->supi);
} else {
ue_context_id = ogs_guti_to_string(amf_ue);
}
return ue_context_id;
}
ogs_sbi_request_t *amf_namf_comm_build_ue_context_transfer(
amf_ue_t *amf_ue, void *data)
{
ogs_sbi_message_t message;
ogs_sbi_request_t *request = NULL;
OpenAPI_ue_context_transfer_req_data_t UeContextTransferReqData;
char *ue_context_id = NULL;
ogs_assert(amf_ue);
ue_context_id = amf_ue_to_context_id(amf_ue);
ogs_assert(ue_context_id);
memset(&UeContextTransferReqData, 0, sizeof(UeContextTransferReqData));
UeContextTransferReqData.access_type = amf_ue->nas.access_type;
UeContextTransferReqData.reason = amf_ue->nas.registration.value;
memset(&message, 0, sizeof(message));
message.h.method = (char *)OGS_SBI_HTTP_METHOD_POST;
message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NAMF_COMM;
message.h.api.version = (char *)OGS_SBI_API_V1;
message.h.resource.component[0] =
(char *)OGS_SBI_RESOURCE_NAME_UE_CONTEXTS;
message.h.resource.component[1] = ue_context_id;
message.h.resource.component[2] =
(char *)OGS_SBI_RESOURCE_NAME_TRANSFER;
message.UeContextTransferReqData = &UeContextTransferReqData;
request = ogs_sbi_build_request(&message);
ogs_expect(request);
if (ue_context_id)
ogs_free(ue_context_id);
return request;
}