open5gs/src/mme/mme_s11_path.c

112 lines
2.6 KiB
C
Raw Normal View History

2017-03-24 09:47:05 +00:00
#define TRACE_MODULE _mme_s11_path
2017-03-23 14:05:40 +00:00
#include "core_debug.h"
#include "core_pkbuf.h"
#include "core_net.h"
2017-04-04 01:49:19 +00:00
#include "mme_event.h"
2017-04-06 10:20:33 +00:00
#include "mme_context.h"
2017-04-04 01:49:19 +00:00
#include "mme_s11_path.h"
2017-03-23 14:05:40 +00:00
2017-04-03 06:27:00 +00:00
static int _gtpv2_c_recv_cb(net_sock_t *sock, void *data)
2017-03-24 04:19:36 +00:00
{
2017-03-26 15:48:33 +00:00
char buf[INET_ADDRSTRLEN];
2017-03-26 16:50:01 +00:00
status_t rv;
2017-03-24 04:19:36 +00:00
event_t e;
pkbuf_t *pkbuf = NULL;
2017-03-27 04:22:42 +00:00
gtp_node_t gnode;
sgw_ctx_t *sgw = NULL;
2017-03-26 15:48:33 +00:00
2017-04-03 06:27:00 +00:00
d_assert(sock, return -1, "Null param");
2017-03-24 04:19:36 +00:00
2017-04-03 06:27:00 +00:00
pkbuf = gtp_read(sock);
2017-03-24 04:19:36 +00:00
if (pkbuf == NULL)
{
2017-04-03 06:27:00 +00:00
if (sock->sndrcv_errno == EAGAIN)
2017-03-24 04:19:36 +00:00
return 0;
return -1;
}
2017-04-03 06:27:00 +00:00
gnode.addr = sock->remote.sin_addr.s_addr;
gnode.port = ntohs(sock->remote.sin_port);
sgw = mme_ctx_sgw_find_by_node(&gnode);
d_assert(sgw, return -1, "Can't find SGW from [%s:%d]",
INET_NTOP(&gnode.addr, buf), gnode.port);
2017-03-26 15:48:33 +00:00
d_trace(1, "S11_PDU is received from SGW[%s:%d]\n",
2017-03-27 04:22:42 +00:00
INET_NTOP(&gnode.addr, buf), gnode.port);
2017-03-24 04:19:36 +00:00
d_trace_hex(1, pkbuf->payload, pkbuf->len);
event_set(&e, EVT_MSG_MME_S11);
2017-04-03 06:27:00 +00:00
event_set_param1(&e, (c_uintptr_t)sock);
event_set_param2(&e, (c_uintptr_t)sgw);
event_set_param3(&e, (c_uintptr_t)pkbuf);
2017-03-26 16:50:01 +00:00
rv = mme_event_send(&e);
if (rv != CORE_OK)
2017-03-26 15:48:33 +00:00
{
2017-03-26 16:50:01 +00:00
d_error("mme_event_send error");
2017-03-26 15:48:33 +00:00
pkbuf_free(pkbuf);
2017-03-26 16:50:01 +00:00
return -1;
2017-03-26 15:48:33 +00:00
}
2017-03-24 04:19:36 +00:00
return 0;
}
2017-03-27 04:22:42 +00:00
status_t mme_s11_listen()
2017-03-23 14:05:40 +00:00
{
2017-03-26 15:48:33 +00:00
status_t rv;
2017-03-27 04:22:42 +00:00
rv = gtp_listen(&mme_self()->s11_sock, _gtpv2_c_recv_cb,
mme_self()->s11_addr, mme_self()->s11_port, NULL);
2017-03-26 15:48:33 +00:00
if (rv != CORE_OK)
{
2017-03-27 04:22:42 +00:00
d_error("Can't establish S11 Path for SGW");
2017-03-26 15:48:33 +00:00
return rv;
}
return CORE_OK;
2017-03-23 14:05:40 +00:00
}
2017-03-27 04:22:42 +00:00
status_t mme_s11_close()
2017-03-23 14:05:40 +00:00
{
2017-03-26 15:48:33 +00:00
status_t rv;
2017-03-27 04:22:42 +00:00
rv = gtp_close(mme_self()->s11_sock);
2017-03-26 15:48:33 +00:00
if (rv != CORE_OK)
{
2017-03-27 04:22:42 +00:00
d_error("Can't close S11 Path for SGW");
2017-03-26 15:48:33 +00:00
return rv;
}
return CORE_OK;
2017-03-23 14:05:40 +00:00
}
2017-04-06 03:23:07 +00:00
status_t mme_s11_send_to_sgw(void *sgw,
c_uint8_t type, c_uint32_t teid, pkbuf_t *pkbuf)
2017-03-23 14:05:40 +00:00
{
2017-04-03 12:13:52 +00:00
gtp_xact_t *xact = NULL;
2017-03-27 04:22:42 +00:00
d_assert(sgw, return CORE_ERROR, "Null param");
2017-04-06 00:57:56 +00:00
d_assert(pkbuf, return CORE_ERROR, "Null param");
2017-03-27 04:22:42 +00:00
2017-04-03 12:13:52 +00:00
xact = gtp_xact_local_create(&mme_self()->gtp_xact_ctx,
mme_self()->s11_sock, sgw);
2017-04-03 05:18:25 +00:00
d_assert(xact, return CORE_ERROR, "Null param");
2017-04-02 13:55:04 +00:00
2017-04-06 03:23:07 +00:00
d_assert(gtp_xact_commit(xact, type, teid, pkbuf) == CORE_OK,
2017-04-03 05:18:25 +00:00
return CORE_ERROR, "xact commit error");
2017-04-02 13:55:04 +00:00
2017-03-30 00:06:56 +00:00
return CORE_OK;
2017-03-23 14:05:40 +00:00
}
2017-04-02 13:30:58 +00:00
2017-04-04 01:49:19 +00:00
#include "mme_s11_build.h"
2017-04-02 13:30:58 +00:00
void test_send()
{
2017-04-06 00:57:56 +00:00
pkbuf_t *pkbuf;
c_uint8_t type;
2017-04-06 03:23:07 +00:00
c_uint32_t teid = 0;
2017-04-06 00:57:56 +00:00
mme_s11_build_create_session_req(&type, &pkbuf, NULL);
2017-04-06 03:23:07 +00:00
mme_s11_send_to_sgw(mme_ctx_sgw_first(), type, teid, pkbuf);
2017-04-02 13:30:58 +00:00
}