open5gs/src/pgw/pgw_handler.c

101 lines
3.0 KiB
C
Raw Normal View History

2017-03-30 15:15:13 +00:00
#define TRACE_MODULE _pgw_handler
#include "core_debug.h"
2017-04-06 14:29:20 +00:00
#include "gtp_types.h"
2017-04-04 02:26:59 +00:00
#include "pgw_event.h"
2017-04-06 14:29:20 +00:00
#include "pgw_context.h"
2017-03-30 15:15:13 +00:00
#include "pgw_path.h"
2017-04-04 02:26:59 +00:00
#include "pgw_handler.h"
2017-03-30 15:15:13 +00:00
2017-04-04 02:26:59 +00:00
void pgw_handle_create_session_request(
2017-03-30 15:15:13 +00:00
gtp_xact_t *xact, gtp_create_session_request_t *req)
{
2017-04-06 00:57:56 +00:00
status_t rv;
2017-04-12 01:05:23 +00:00
c_int8_t apn[MAX_APN_LEN];
pdn_t *pdn = NULL;
2017-04-06 00:57:56 +00:00
pkbuf_t *pkbuf;
2017-04-03 05:18:25 +00:00
gtp_message_t gtp_message;
2017-04-06 00:57:56 +00:00
c_uint8_t type = GTP_CREATE_SESSION_RESPONSE_TYPE;
2017-04-03 05:18:25 +00:00
gtp_create_session_response_t *rsp = &gtp_message.create_session_response;
2017-04-06 14:29:20 +00:00
gtp_cause_t cause;
gtp_f_teid_t *sgw_f_teid;
gtp_f_teid_t pgw_f_teid;
2017-04-08 01:50:29 +00:00
pgw_sess_t *sess = NULL;
2017-04-06 14:29:20 +00:00
d_assert(xact, return, "Null param");
d_assert(req, return, "Null param");
2017-04-12 01:05:23 +00:00
if (req->access_point_name.presence == 0)
{
d_error("No APN");
return;
}
2017-04-06 14:29:20 +00:00
if (req->sender_f_teid_for_control_plane.presence == 0)
{
d_error("No Sender F-TEID for control plance");
return;
}
2017-04-12 01:05:23 +00:00
memcpy(apn, req->access_point_name.data, req->access_point_name.len);
apn[req->access_point_name.len] = 0;
pdn = pgw_pdn_find_by_apn(apn);
if (!pdn)
{
d_error("No PDN Context-APN[%s]", apn);
return;
}
2017-04-06 14:29:20 +00:00
sgw_f_teid = req->sender_f_teid_for_control_plane.data;
if (!(sgw_f_teid->ipv4 == 1 && sgw_f_teid->ipv6 == 0 &&
sgw_f_teid->interface_type == GTP_F_TEID_S5_S8_SGW_GTP_C))
{
d_error("Invalid Parameter(ipv4:%d,ipv6:%d,type:%d",
sgw_f_teid->ipv4, sgw_f_teid->ipv6,
sgw_f_teid->interface_type);
return;
}
2017-04-08 01:50:29 +00:00
sess = pgw_sess_add();
d_assert(sess, return, "sess_add failed");
2017-04-06 14:29:20 +00:00
2017-04-08 01:50:29 +00:00
sess->sgw_teid = ntohl(sgw_f_teid->teid);
2017-04-11 10:14:18 +00:00
sess->sgw_addr = sgw_f_teid->ipv4_addr;
2017-04-06 14:29:20 +00:00
2017-04-03 05:18:25 +00:00
memset(&gtp_message, 0, sizeof(gtp_message_t));
2017-04-06 14:29:20 +00:00
memset(&cause, 0, sizeof(cause));
cause.cause_value = GTP_CAUSE_REQUEST_ACCEPTED;
2017-04-03 05:18:25 +00:00
rsp->cause.presence = 1;
2017-04-06 14:29:20 +00:00
rsp->cause.len = sizeof(cause);
rsp->cause.data = &cause;
memset(&pgw_f_teid, 0, sizeof(gtp_f_teid_t));
pgw_f_teid.ipv4 = 1;
pgw_f_teid.interface_type = GTP_F_TEID_S5_S8_PGW_GTP_C;
pgw_f_teid.ipv4_addr = pgw_self()->s5c_addr;
2017-04-08 01:50:29 +00:00
pgw_f_teid.teid = htonl(sess->teid);
2017-04-06 14:29:20 +00:00
rsp->pgw_s5_s8__s2a_s2b_f_teid_for_pmip_based_interface_or_for_gtp_based_control_plane_interface.
presence = 1;
rsp->pgw_s5_s8__s2a_s2b_f_teid_for_pmip_based_interface_or_for_gtp_based_control_plane_interface.
data = &pgw_f_teid;
rsp->pgw_s5_s8__s2a_s2b_f_teid_for_pmip_based_interface_or_for_gtp_based_control_plane_interface.
len = GTP_F_TEID_IPV4_LEN;
2017-04-03 05:18:25 +00:00
2017-04-12 01:05:23 +00:00
rsp->pdn_address_allocation.presence = 1;
rsp->pdn_address_allocation.data = &pdn->paa;
rsp->pdn_address_allocation.len = PAA_IPV4_LEN;
rsp->apn_restriction.presence = 1;
rsp->apn_restriction.u8 = GTP_APN_NO_RESTRICTION;
2017-04-06 00:57:56 +00:00
rv = gtp_build_msg(&pkbuf, type, &gtp_message);
d_assert(rv == CORE_OK, return, "gtp build failed");
2017-04-08 01:50:29 +00:00
pgw_s5c_send_to_sgw(xact, type, sess->sgw_teid, pkbuf);
2017-03-30 15:15:13 +00:00
}