open5gs/src/mme/s11_path.c

111 lines
2.5 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-03-26 06:34:34 +00:00
#include "event.h"
2017-03-28 07:35:57 +00:00
#include "context.h"
2017-03-23 14:15:55 +00:00
#include "s11_path.h"
2017-03-23 14:05:40 +00:00
2017-03-27 04:22:42 +00:00
static int _gtpv2_c_recv_cb(net_sock_t *net_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-03-24 04:19:36 +00:00
d_assert(net_sock, return -1, "Null param");
2017-03-27 04:22:42 +00:00
gnode.addr = net_sock->remote.sin_addr.s_addr;
gnode.port = net_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);
pkbuf = gtp_read(net_sock);
2017-03-24 04:19:36 +00:00
if (pkbuf == NULL)
{
if (net_sock->sndrcv_errno == EAGAIN)
return 0;
return -1;
}
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-03-27 04:22:42 +00:00
event_set_param1(&e, (c_uintptr_t)sgw);
2017-03-24 04:19:36 +00:00
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-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-02 13:30:58 +00:00
status_t mme_s11_send_to_sgw(void *sgw, gtp_message_t *gtp_message)
2017-03-23 14:05:40 +00:00
{
2017-03-30 13:23:47 +00:00
gtp_xact_t *xact;
2017-03-27 04:22:42 +00:00
d_assert(sgw, return CORE_ERROR, "Null param");
2017-04-02 13:30:58 +00:00
d_assert(gtp_message, return CORE_ERROR, "Null param");
2017-03-27 04:22:42 +00:00
2017-04-02 13:55:04 +00:00
xact = gtp_xact_local_create(&mme_self()->gtp_xact_ctx,
mme_self()->s11_sock, sgw, gtp_message);
d_assert(xact, return CORE_ERROR, "gtp_xact_local_create failed");
d_assert(gtp_send(xact->sock, xact->gnode, xact->pkbuf) == CORE_OK,
gtp_xact_delete(xact); return CORE_ERROR, "gtp_send error");
#if 1 /* FIXME */
2017-03-30 13:23:47 +00:00
gtp_xact_delete(xact);
2017-04-02 13:55:04 +00:00
#endif
2017-03-29 14:19:31 +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
#include "s11_build.h"
void test_send()
{
gtp_message_t gtp_message;
s11_build_create_session_req(&gtp_message, NULL);
mme_s11_send_to_sgw(mme_ctx_sgw_first(), &gtp_message);
}