[SGsAP] Basic operation done

This commit is contained in:
Sukchan Lee 2019-06-22 00:28:21 +09:00
parent bbc594330b
commit 652cfa70d5
9 changed files with 185 additions and 21 deletions

View File

@ -7,7 +7,7 @@ libmme_la_SOURCES = \
mme-event.h mme-context.h \
ogs-sctp.h \
s1ap-build.h s1ap-handler.h s1ap-conv.h s1ap-path.h \
sgsap-build.h sgsap-conv.h sgsap-path.h \
sgsap-build.h sgsap-handler.h sgsap-conv.h sgsap-path.h \
mme-fd-path.h mme-s6a-handler.h \
nas-conv.h nas-security.h nas-path.h \
emm-handler.h emm-build.h \
@ -18,7 +18,7 @@ libmme_la_SOURCES = \
mme-init.c mme-event.c mme-context.c \
ogs-sctp.c \
s1ap-sm.c s1ap-build.c s1ap-handler.c s1ap-conv.c s1ap-path.c \
sgsap-sm.c sgsap-build.c sgsap-conv.c sgsap-path.c \
sgsap-sm.c sgsap-build.c sgsap-handler.c sgsap-conv.c sgsap-path.c \
mme-fd-path.c mme-s6a-handler.c \
nas-conv.c nas-security.c nas-path.c \
emm-sm.c emm-handler.c emm-build.c \

View File

@ -46,6 +46,7 @@ typedef struct gtp_xact_s gtp_xact_t;
typedef struct fd_config_s fd_config_t;
typedef uint32_t mme_m_tmsi_t;
typedef uint32_t mme_p_tmsi_t;
typedef enum {
SGW_SELECT_RR = 0, /* Default SGW Selection Method */
@ -269,6 +270,7 @@ struct mme_ue_s {
nas_mobile_identity_imsi_t nas_mobile_identity_imsi;
mme_m_tmsi_t *m_tmsi;
mme_p_tmsi_t p_tmsi;
nas_guti_t guti;
int guti_present;

View File

@ -535,22 +535,9 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e)
ogs_assert(vlr);
ogs_assert(OGS_FSM_STATE(&vlr->sm));
#if 0
rc = s1ap_decode_pdu(&s1ap_message, pkbuf);
if (rc == OGS_OK) {
#endif
e->vlr = vlr;
#if 0
e->s1ap_message = &s1ap_message;
#endif
ogs_fsm_dispatch(&vlr->sm, e);
#if 0
} else {
ogs_error("Cannot process SGSAP message");
}
e->vlr = vlr;
ogs_fsm_dispatch(&vlr->sm, e);
s1ap_free_pdu(&s1ap_message);
#endif
ogs_pkbuf_free(pkbuf);
break;

99
src/mme/sgsap-handler.c Normal file
View File

@ -0,0 +1,99 @@
/*
* 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 "sgsap-types.h"
#include "mme-context.h"
#include "mme-path.h"
#include "nas-conv.h"
#include "nas-path.h"
void sgsap_handler_location_update_accept(mme_vlr_t *vlr, ogs_pkbuf_t *pkbuf)
{
ogs_tlv_t *root = NULL, *iter = NULL;
mme_ue_t *mme_ue = NULL;
enb_ue_t *enb_ue = NULL;
nas_mobile_identity_imsi_t *nas_mobile_identity_imsi = NULL;
int nas_mobile_identity_imsi_len = 0;
nas_lai_t *lai = NULL;
nas_mobile_identity_tmsi_t *nas_mobile_identity_tmsi = NULL;
ogs_assert(vlr);
ogs_assert(pkbuf);
ogs_pkbuf_pull(pkbuf, 1);
root = ogs_tlv_parse_block(pkbuf->len, pkbuf->data, OGS_TLV_MODE_T1_L1);
ogs_assert(root);
iter = root;
while (iter) {
switch (iter->type) {
case SGSAP_IE_IMSI_TYPE:
nas_mobile_identity_imsi = iter->value;
nas_mobile_identity_imsi_len = iter->length;
break;
case SGSAP_IE_LAI_TYPE:
lai = iter->value;
break;
case SGSAP_IE_MOBILE_IDENTITY_TYPE:
nas_mobile_identity_tmsi = iter->value;
break;
}
iter = iter->next;
}
ogs_tlv_free_all(root);
ogs_assert(nas_mobile_identity_imsi && lai && nas_mobile_identity_tmsi);
ogs_assert(nas_mobile_identity_imsi_len == SGSAP_IE_IMSI_LEN);
if (nas_mobile_identity_imsi->type == NAS_MOBILE_IDENTITY_IMSI) {
char imsi_bcd[MAX_IMSI_BCD_LEN+1];
nas_imsi_to_bcd(nas_mobile_identity_imsi,
nas_mobile_identity_imsi_len, imsi_bcd);
mme_ue = mme_ue_find_by_imsi_bcd(imsi_bcd);
} else {
ogs_error("Not supported Identity type[%d]",
nas_mobile_identity_imsi->type);
goto error;
}
ogs_assert(mme_ue);
if (nas_mobile_identity_tmsi->type == NAS_MOBILE_IDENTITY_TMSI) {
mme_ue->p_tmsi = ntohl(nas_mobile_identity_tmsi->tmsi);
} else {
ogs_error("Not supported Identity type[%d]",
nas_mobile_identity_tmsi->type);
goto error;
}
nas_send_attach_accept(mme_ue);
return;
error:
enb_ue = mme_ue->enb_ue;
ogs_assert(enb_ue);
mme_send_delete_session_or_ue_context_release(mme_ue, enb_ue);
}

35
src/mme/sgsap-handler.h Normal file
View File

@ -0,0 +1,35 @@
/*
* 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/>.
*/
#ifndef SGSAP_HANDLER_H
#define SGSAP_HANDLER_H
#include "sgsap-types.h"
#ifdef __cplusplus
extern "C" {
#endif
void sgsap_handler_location_update_accept(mme_vlr_t *vlr, ogs_pkbuf_t *pkbuf);
#ifdef __cplusplus
}
#endif
#endif /* SGSAP_HANDLER_H */

View File

@ -24,6 +24,7 @@
#include "mme-sm.h"
#include "sgsap-path.h"
#include "sgsap-handler.h"
static void sgsap_connect_timeout(void *data);
@ -92,6 +93,8 @@ void sgsap_state_will_connect(ogs_fsm_t *s, mme_event_t *e)
void sgsap_state_connected(ogs_fsm_t *s, mme_event_t *e)
{
mme_vlr_t *vlr = NULL;
ogs_pkbuf_t *pkbuf = NULL;
uint8_t type;
ogs_assert(s);
ogs_assert(e);
@ -110,6 +113,17 @@ void sgsap_state_connected(ogs_fsm_t *s, mme_event_t *e)
OGS_FSM_TRAN(s, sgsap_state_will_connect);
break;
case MME_EVT_SGSAP_MESSAGE:
pkbuf = e->pkbuf;
ogs_assert(pkbuf);
type = *(unsigned char *)(pkbuf->data);
switch (type) {
case SGSAP_LOCATION_UPDATE_ACCEPT:
sgsap_handler_location_update_accept(vlr, pkbuf);
break;
default:
ogs_warn("Not implemented(type:%d)", type);
break;
}
break;
default:
ogs_error("Unknown event %s", mme_event_get_name(e));

View File

@ -98,6 +98,8 @@ ogs_socknode_t *testsctp_client(const char *ipstr)
return node;
}
static ogs_sockaddr_t sctp_last_addr;
ogs_pkbuf_t *testsctp_read(ogs_socknode_t *node)
{
int size;
@ -110,7 +112,7 @@ ogs_pkbuf_t *testsctp_read(ogs_socknode_t *node)
ogs_pkbuf_put(recvbuf, MAX_SDU_LEN);
size = ogs_sctp_recvdata(node->sock,
recvbuf->data, MAX_SDU_LEN, NULL, NULL);
recvbuf->data, MAX_SDU_LEN, &sctp_last_addr, NULL);
if (size <= 0) {
ogs_error("sgsap_recv() failed");
return NULL;
@ -127,7 +129,7 @@ int testenb_s1ap_send(ogs_socknode_t *node, ogs_pkbuf_t *sendbuf)
int testvlr_sgsap_send(ogs_socknode_t *node, ogs_pkbuf_t *sendbuf)
{
return sgsap_send(node->sock, sendbuf, NULL, 0);
return sgsap_send(node->sock, sendbuf, &sctp_last_addr, 0);
}
ogs_socknode_t *testenb_gtpu_server(const char *ipstr)
@ -2854,3 +2856,24 @@ int testgtpu_build_slacc_rs(ogs_pkbuf_t **pkbuf, int i)
return OGS_OK;
}
int testsgsap_location_update_accept(ogs_pkbuf_t **pkbuf, int i)
{
char *payload[TESTS1AP_MAX_MESSAGE] = {
"0a01082926240000 111893040509f107 09260e05f49ee88e 64",
"",
"",
};
uint16_t len[TESTS1AP_MAX_MESSAGE] = {
25,
0,
0,
};
char hexbuf[MAX_SDU_LEN];
*pkbuf = ogs_pkbuf_alloc(NULL, MAX_SDU_LEN);
ogs_pkbuf_put_data(*pkbuf,
OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]);
return OGS_OK;
}

View File

@ -129,6 +129,8 @@ int testgtpu_build_ping(ogs_pkbuf_t **sendbuf,
const char *src_ip, const char *dst_ip);
int testgtpu_build_slacc_rs(ogs_pkbuf_t **sendbuf, int i);
int testsgsap_location_update_accept(ogs_pkbuf_t **pkbuf, int i);
#ifdef __cplusplus
}
#endif

View File

@ -214,8 +214,11 @@ static void test1_func(abts_case *tc, void *data)
ogs_pkbuf_free(recvbuf);
/* Send SGsAP-Location-Update-Accept */
rv = testsgsap_location_update_accept(&sendbuf, 0);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testvlr_sgsap_send(sgsap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
#if 0
/* Receive Initial Context Setup Request +
* Attach Accept +
* Activate Default Bearer Context Request */
@ -321,7 +324,6 @@ static void test1_func(abts_case *tc, void *data)
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_s1ap_send(s1ap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
#endif
/********** Remove Subscriber in Database */
doc = BCON_NEW("imsi", BCON_UTF8("262420000118139"));