open5gs/src/mme/mme_gtp_path.c

93 lines
2.0 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-08-31 02:05:00 +00:00
#include "mme_gtp_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-09-01 16:48:09 +00:00
c_uint32_t addr;
c_uint16_t port;
2017-04-06 11:10:00 +00:00
mme_sgw_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-09-01 16:48:09 +00:00
addr = sock->remote.sin_addr.s_addr;
port = ntohs(sock->remote.sin_port);
2017-04-03 06:27:00 +00:00
2017-09-01 16:48:09 +00:00
sgw = mme_sgw_find(addr, port);
2017-04-03 06:27:00 +00:00
d_assert(sgw, return -1, "Can't find SGW from [%s:%d]",
2017-09-01 16:48:09 +00:00
INET_NTOP(&addr, buf), port);
sgw->sock = sock; /* Is it needed? */
2017-04-03 06:27:00 +00:00
2017-07-31 13:35:25 +00:00
d_trace(10, "S11_PDU is received from SGW[%s:%d]\n",
2017-09-01 16:48:09 +00:00
INET_NTOP(&addr, buf), port);
2017-07-31 13:35:25 +00:00
d_trace_hex(10, pkbuf->payload, pkbuf->len);
2017-03-24 04:19:36 +00:00
2017-08-25 15:25:55 +00:00
event_set(&e, MME_EVT_S11_MESSAGE);
event_set_param1(&e, (c_uintptr_t)sgw);
event_set_param2(&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-08-31 02:05:00 +00:00
status_t mme_gtp_open()
2017-03-23 14:05:40 +00:00
{
2017-03-26 15:48:33 +00:00
status_t rv;
mme_sgw_t *sgw = mme_sgw_first();
2017-03-26 15:48:33 +00:00
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;
}
/* socket descriptor needs in gnode when packet is sending initilly */
while(sgw)
{
sgw->sock = mme_self()->s11_sock;
sgw = mme_sgw_next(sgw);
}
2017-03-26 15:48:33 +00:00
return CORE_OK;
2017-03-23 14:05:40 +00:00
}
2017-08-31 02:05:00 +00:00
status_t mme_gtp_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
}