blob: b7758b3f51b4336c3e3486426e355c338ffc77cd [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2 * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
3 * Copyright (c) 2017 Intel Corporation
4 * Copyright (c) 2019, Infosys Ltd.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <arpa/inet.h>
22#include <unistd.h>
23#include <string.h>
24#include <pthread.h>
25
26#include "log.h"
27#include "err_codes.h"
28#include "message_queues.h"
29#include "ipc_api.h"
30#include "gtpv2c.h"
31#include "gtpv2c_ie.h"
32#include "msgType.h"
33#include "../../gtpV2Codec/gtpV2StackWrappers.h"
34/************************************************************************
35Current file : Stage 1 handler.
36ATTACH stages :
37 Stage 1 : detach request -->delete session
38**************************************************************************/
39
40/****Globals and externs ***/
41
42/*S11 CP communication parameters*/
43extern int g_s11_fd;
44extern struct sockaddr_in g_s11_cp_addr;
45extern socklen_t g_s11_serv_size;
46extern volatile uint32_t g_s11_sequence;
47static char buf[S11_DTCHREQ_STAGE1_BUF_SIZE];
48
49struct thread_pool *g_tpool;
50
51extern struct GtpV2Stack* gtpStack_gp;
52extern volatile uint32_t g_s11_sequence;
53
54struct MsgBuffer* dsReqMsgBuf_p = NULL;
55/****Global and externs end***/
56
57/**
58* Stage specific message processing.
59*/
60static int
61delete_session_processing(struct DS_Q_msg *ds_msg)
62{
63 GtpV2MessageHeader gtpHeader;
64 gtpHeader.msgType = GTP_DELETE_SESSION_REQ;
65 gtpHeader.sequenceNumber = g_s11_sequence;
66 gtpHeader.teidPresent = true;
67 gtpHeader.teid = ds_msg->s11_sgw_c_fteid.header.teid_gre;
68
69 DeleteSessionRequestMsgData msgData;
70 memset(&msgData, 0, sizeof(DeleteSessionRequestMsgData));
71
72 msgData.indicationFlagsIePresent = true;
73 msgData.indicationFlags.iOI = true;
74
75 msgData.linkedEpsBearerIdIePresent = true;
76 msgData.linkedEpsBearerId.epsBearerId = ds_msg->bearer_id;
77
78 GtpV2Stack_buildGtpV2Message(gtpStack_gp, dsReqMsgBuf_p, &gtpHeader, &msgData);
79 g_s11_sequence++;
80
81 sendto(g_s11_fd,
82 MsgBuffer_getDataPointer(dsReqMsgBuf_p),
83 MsgBuffer_getBufLen(dsReqMsgBuf_p), 0,
84 (struct sockaddr*)&g_s11_cp_addr, g_s11_serv_size);
85 log_msg(LOG_INFO, "Send delete session request\n");
86
87 MsgBuffer_reset(dsReqMsgBuf_p);
88
89 return SUCCESS;
90}
91
92
93/**
94* Thread function for stage.
95*/
96void*
97delete_session_handler(void *data)
98{
99 log_msg(LOG_INFO, "Delete session handler initialized\n");
100
101 delete_session_processing((struct DS_Q_msg *)data);
102 return NULL;
103}
104