open5gs/src/mme/sgsap-path.c

297 lines
7.3 KiB
C
Raw Normal View History

2019-06-16 06:40:26 +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/>.
*/
#include "ogs-sctp.h"
2019-06-16 09:20:40 +00:00
#include "mme-event.h"
#include "mme-sm.h"
2019-06-20 09:20:32 +00:00
2019-06-16 06:40:26 +00:00
#include "sgsap-path.h"
2023-04-04 12:53:39 +00:00
int sgsap_open(void)
2019-06-16 06:40:26 +00:00
{
2019-06-16 09:20:40 +00:00
mme_vlr_t *vlr = NULL;
ogs_list_for_each(&mme_self()->vlr_list, vlr) {
mme_event_t e;
2020-06-22 03:07:14 +00:00
memset(&e, 0, sizeof(e));
2019-06-16 09:20:40 +00:00
e.vlr = vlr;
ogs_fsm_init(&vlr->sm, sgsap_state_initial, sgsap_state_final, &e);
2019-06-16 09:20:40 +00:00
}
2019-06-16 06:40:26 +00:00
return OGS_OK;
}
2023-04-04 12:53:39 +00:00
void sgsap_close(void)
2019-06-16 06:40:26 +00:00
{
2019-06-16 09:20:40 +00:00
mme_vlr_t *vlr = NULL;
ogs_list_for_each(&mme_self()->vlr_list, vlr) {
mme_event_t e;
2020-06-22 03:07:14 +00:00
memset(&e, 0, sizeof(e));
2019-06-16 09:20:40 +00:00
e.vlr = vlr;
ogs_fsm_fini(&vlr->sm, &e);
}
2019-06-16 06:40:26 +00:00
}
int sgsap_send(ogs_sock_t *sock, ogs_pkbuf_t *pkbuf,
ogs_sockaddr_t *addr, uint16_t stream_no)
{
int sent;
ogs_assert(sock);
ogs_assert(pkbuf);
sent = ogs_sctp_sendmsg(sock, pkbuf->data, pkbuf->len,
2019-09-13 12:07:47 +00:00
addr, OGS_SCTP_SGSAP_PPID, stream_no);
2019-06-16 06:40:26 +00:00
if (sent < 0 || sent != pkbuf->len) {
ogs_error("ogs_sctp_sendmsg(len:%d,ssn:%d) error (%d:%s)",
pkbuf->len, stream_no, errno, strerror(errno));
ogs_pkbuf_free(pkbuf);
2019-06-16 06:40:26 +00:00
return OGS_ERROR;
}
ogs_pkbuf_free(pkbuf);
2019-06-16 06:40:26 +00:00
return OGS_OK;
}
2019-06-16 07:47:20 +00:00
int sgsap_send_to_vlr_with_sid(
mme_vlr_t *vlr, ogs_pkbuf_t *pkbuf, uint16_t stream_no)
2019-06-16 06:40:26 +00:00
{
char buf[OGS_ADDRSTRLEN];
ogs_sock_t *sock = NULL;;
ogs_assert(vlr);
ogs_assert(pkbuf);
sock = vlr->sock;
2019-06-16 06:40:26 +00:00
ogs_assert(sock);
ogs_debug(" VLR-IP[%s]", OGS_ADDR(vlr->addr, buf));
return sgsap_send(sock, pkbuf, vlr->addr, stream_no);
2019-06-16 06:40:26 +00:00
}
2019-06-16 07:47:20 +00:00
int sgsap_send_to_vlr(mme_ue_t *mme_ue, ogs_pkbuf_t *pkbuf)
{
2019-07-21 11:25:29 +00:00
mme_csmap_t *csmap = NULL;
2019-06-16 07:47:20 +00:00
mme_vlr_t *vlr = NULL;
2019-07-21 11:25:29 +00:00
2019-06-16 07:47:20 +00:00
ogs_assert(pkbuf);
2019-07-21 11:25:29 +00:00
ogs_assert(mme_ue);
csmap = mme_ue->csmap;
ogs_assert(csmap);
vlr = csmap->vlr;
2019-06-16 07:47:20 +00:00
ogs_assert(vlr);
2019-07-21 11:25:29 +00:00
ogs_debug(" TAI[PLMN_ID:%06x,TAC:%d]",
2019-09-13 12:07:47 +00:00
ogs_plmn_id_hexdump(&csmap->tai.nas_plmn_id), csmap->tai.tac);
2019-07-21 11:25:29 +00:00
ogs_debug(" LAI[PLMN_ID:%06x,LAC:%d]",
2019-09-13 12:07:47 +00:00
ogs_plmn_id_hexdump(&csmap->lai.nas_plmn_id), csmap->lai.lac);
2019-07-21 11:25:29 +00:00
2019-06-16 07:47:20 +00:00
return sgsap_send_to_vlr_with_sid(vlr, pkbuf, mme_ue->vlr_ostream_id);
}
2019-06-20 09:20:32 +00:00
int sgsap_send_location_update_request(mme_ue_t *mme_ue)
2019-06-20 09:20:32 +00:00
{
int rv;
ogs_pkbuf_t *pkbuf = NULL;
ogs_assert(mme_ue);
2019-06-22 03:11:07 +00:00
ogs_debug("[SGSAP] LOCATION-UPDATE-REQUEST");
ogs_debug(" IMSI[%s]", mme_ue->imsi_bcd);
2019-06-20 09:20:32 +00:00
pkbuf = sgsap_build_location_update_request(mme_ue);
if (!pkbuf) {
ogs_error("sgsap_build_location_update_request() failed");
return OGS_ERROR;
}
2019-06-20 09:20:32 +00:00
rv = sgsap_send_to_vlr(mme_ue, pkbuf);
ogs_expect(rv == OGS_OK);
return rv;
2019-06-20 09:20:32 +00:00
}
2019-06-22 03:11:07 +00:00
int sgsap_send_tmsi_reallocation_complete(mme_ue_t *mme_ue)
2019-06-22 03:11:07 +00:00
{
int rv;
ogs_pkbuf_t *pkbuf = NULL;
ogs_assert(mme_ue);
ogs_debug("[SGSAP] TMSI-REALLOCATION-COMPLETE");
ogs_debug(" IMSI[%s]", mme_ue->imsi_bcd);
2019-06-22 03:11:07 +00:00
pkbuf = sgsap_build_tmsi_reallocation_complete(mme_ue);
if (!pkbuf) {
ogs_error("sgsap_build_tmsi_reallocation_complete() failed");
return OGS_ERROR;
}
rv = sgsap_send_to_vlr(mme_ue, pkbuf);
ogs_expect(rv == OGS_OK);
return rv;
}
int sgsap_send_detach_indication(mme_ue_t *mme_ue)
{
int rv;
ogs_pkbuf_t *pkbuf = NULL;
ogs_assert(mme_ue);
2019-07-05 09:13:32 +00:00
pkbuf = sgsap_build_detach_indication(mme_ue);
if (!pkbuf) {
ogs_error("sgsap_build_detach_indication() failed");
return OGS_ERROR;
}
2019-06-22 03:11:07 +00:00
rv = sgsap_send_to_vlr(mme_ue, pkbuf);
ogs_expect(rv == OGS_OK);
return rv;
2019-06-22 03:11:07 +00:00
}
2019-07-07 00:47:32 +00:00
int sgsap_send_mo_csfb_indication(mme_ue_t *mme_ue)
2019-07-07 00:47:32 +00:00
{
int rv;
ogs_pkbuf_t *pkbuf = NULL;
ogs_assert(mme_ue);
ogs_debug("[SGSAP] MO-CSFB-INDICATION");
ogs_debug(" IMSI[%s]", mme_ue->imsi_bcd);
pkbuf = sgsap_build_mo_csfb_indication(mme_ue);
if (!pkbuf) {
ogs_error("sgsap_build_mo_csfb_indication() failed");
return OGS_ERROR;
}
2019-07-07 00:47:32 +00:00
rv = sgsap_send_to_vlr(mme_ue, pkbuf);
ogs_expect(rv == OGS_OK);
return rv;
}
int sgsap_send_paging_reject(mme_ue_t *mme_ue, uint8_t sgs_cause)
{
int rv;
ogs_pkbuf_t *pkbuf = NULL;
ogs_assert(mme_ue);
ogs_debug("[SGSAP] PAGING-REJECT");
ogs_debug(" IMSI[%s]", mme_ue->imsi_bcd);
pkbuf = sgsap_build_paging_reject(
&mme_ue->nas_mobile_identity_imsi,
SGSAP_IE_IMSI_LEN, sgs_cause);
if (!pkbuf) {
ogs_error("sgsap_build_paging_reject() failed");
return OGS_ERROR;
}
rv = sgsap_send_to_vlr(mme_ue, pkbuf);
ogs_expect(rv == OGS_OK);
return rv;
2019-07-07 00:47:32 +00:00
}
2019-07-07 01:16:21 +00:00
int sgsap_send_service_request(mme_ue_t *mme_ue, uint8_t emm_mode)
2019-07-08 09:15:19 +00:00
{
int rv;
ogs_pkbuf_t *pkbuf = NULL;
ogs_assert(mme_ue);
2019-07-08 12:03:39 +00:00
ogs_debug("[SGSAP] SERVICE-REQUEST");
2019-07-08 09:15:19 +00:00
ogs_debug(" IMSI[%s]", mme_ue->imsi_bcd);
ogs_debug(" SERVICE_INDICATOR[%d]", mme_ue->service_indicator);
2019-07-09 00:27:45 +00:00
ogs_debug(" EMM_MODE[%d]", emm_mode);
2019-07-08 09:15:19 +00:00
2019-07-09 00:27:45 +00:00
pkbuf = sgsap_build_service_request(mme_ue, emm_mode);
if (!pkbuf) {
ogs_error("sgsap_build_service_request() failed");
return OGS_ERROR;
}
2019-07-08 09:15:19 +00:00
rv = sgsap_send_to_vlr(mme_ue, pkbuf);
ogs_expect(rv == OGS_OK);
return rv;
2019-07-08 09:15:19 +00:00
}
int sgsap_send_reset_ack(mme_vlr_t *vlr)
2019-07-07 01:16:21 +00:00
{
int rv;
ogs_pkbuf_t *pkbuf = NULL;
ogs_assert(vlr);
ogs_debug("[SGSAP] RESET-ACK");
pkbuf = sgsap_build_reset_ack(vlr);
if (!pkbuf) {
ogs_error("sgsap_build_reset_ack() failed");
return OGS_ERROR;
}
2019-07-07 01:16:21 +00:00
rv = sgsap_send_to_vlr_with_sid(vlr, pkbuf, 0);
ogs_expect(rv == OGS_OK);
return rv;
2019-07-07 01:16:21 +00:00
}
2019-07-13 02:51:28 +00:00
int sgsap_send_uplink_unitdata(mme_ue_t *mme_ue,
2020-05-23 02:24:48 +00:00
ogs_nas_eps_message_container_t *nas_message_container)
2019-07-13 02:51:28 +00:00
{
int rv;
ogs_pkbuf_t *pkbuf = NULL;
ogs_assert(mme_ue);
ogs_assert(nas_message_container);
ogs_debug("[SGSAP] UPLINK-UNITDATA");
ogs_debug(" IMSI[%s]", mme_ue->imsi_bcd);
ogs_log_hexdump(OGS_LOG_DEBUG,
nas_message_container->buffer, nas_message_container->length);
pkbuf = sgsap_build_uplink_unidata(mme_ue, nas_message_container);
if (!pkbuf) {
ogs_error("sgsap_build_uplink_unidata() failed");
return OGS_ERROR;
}
2019-07-13 02:51:28 +00:00
rv = sgsap_send_to_vlr(mme_ue, pkbuf);
ogs_expect(rv == OGS_OK);
return rv;
2019-07-13 02:51:28 +00:00
}
int sgsap_send_ue_unreachable(mme_ue_t *mme_ue, uint8_t sgs_cause)
{
int rv;
ogs_pkbuf_t *pkbuf = NULL;
ogs_assert(mme_ue);
ogs_debug("[SGSAP] UE-UNREACHABLE");
ogs_debug(" IMSI[%s]", mme_ue->imsi_bcd);
ogs_debug(" CAUSE[%d]", sgs_cause);
pkbuf = sgsap_build_ue_unreachable(mme_ue, sgs_cause);
if (!pkbuf) {
ogs_error("sgsap_build_ue_unreachable() failed");
return OGS_ERROR;
}
rv = sgsap_send_to_vlr(mme_ue, pkbuf);
ogs_expect(rv == OGS_OK);
return rv;
2022-07-30 05:44:34 +00:00
}