blob: e18cc37eac63472e9b721699facf7f7dee10af56 [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2 * Copyright (c) 2019, Infosys Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <pthread.h>
20#include <string.h>
21
22#include "log.h"
23#include "err_codes.h"
24#include "message_queues.h"
25#include "ipc_api.h"
26#include "s11_structs.h"
27#include "msgType.h"
28//#include "stage7_info.h"
29#include "gtpv2c.h"
30#include "gtpv2c_ie.h"
31#include "../../gtpV2Codec/gtpV2StackWrappers.h"
32
33/************************************************************************
34Current file : Stage 7 handler. To listen MB from mme-app and fwd to CP
35ATTACH stages :
36 Stage 1 : IAM-->[stage1 handler]-->AIR, ULR
37 Stage 2 : AIA, ULA -->[stage2 handler]--> Auth req
38 Stage 3 : Auth resp-->[stage3 handler]-->Sec mode cmd
39 Stage 4 : sec mode resp-->[stage4 handler]-->esm infor req
40 Stage 5 : esm infor resp-->[stage5 handler]-->create session
41 Stage 6 : create session resp-->[stage6 handler]-->init ctx setup
42--> Stage 7 : attach complete-->[stage7 handler]-->modify bearer
43**************************************************************************/
44
45/****Globals and externs ***/
46
47
48extern int g_s11_fd;
49extern struct sockaddr_in g_s11_cp_addr;
50extern socklen_t g_s11_serv_size;
51/*TODO: S11 protocol sequence number - need to make it atomic. multiple thread to access this*/
52extern volatile uint32_t g_s11_sequence;
53
54struct MsgBuffer* rbReqMsgBuf_p = NULL;
55extern struct GtpV2Stack* gtpStack_gp;
56
57
58/****Global and externs end***/
59/**
60* Stage specific message processing.
61*/
62static int
63release_bearer_processing(struct RB_Q_msg *rb_msg)
64{
65 GtpV2MessageHeader gtpHeader;
66 gtpHeader.msgType = GTP_RELEASE_BEARER_REQ;
67 gtpHeader.sequenceNumber = g_s11_sequence;
68 gtpHeader.teidPresent = true;
69 gtpHeader.teid = rb_msg->s11_sgw_c_fteid.header.teid_gre;
70
71 g_s11_sequence++;
72
73 ReleaseAccessBearersRequestMsgData msgData;
74 memset(&msgData, 0, sizeof(msgData));
75
76 msgData.indicationFlagsIePresent = true;
77 msgData.indicationFlags.iOI = true;
78
79 GtpV2Stack_buildGtpV2Message(gtpStack_gp, rbReqMsgBuf_p, &gtpHeader, &msgData);
80
81 sendto(g_s11_fd,
82 MsgBuffer_getDataPointer(rbReqMsgBuf_p),
83 MsgBuffer_getBufLen(rbReqMsgBuf_p), 0,
84 (struct sockaddr*)&g_s11_cp_addr,
85 g_s11_serv_size);
86 //TODO " error chk, eagain etc?
87 log_msg(LOG_INFO, "Release Bearer sent, len - %d bytes.\n", MsgBuffer_getBufLen(rbReqMsgBuf_p));
88
89 MsgBuffer_reset(rbReqMsgBuf_p);
90
91 return SUCCESS;
92
93}
94
95
96/**
97* Thread function for stage.
98*/
99void*
100release_bearer_handler(void *data)
101{
102
103 log_msg(LOG_INFO, "Release bearer handler initialized\n");
104
105 release_bearer_processing((struct RB_Q_msg *)data);
106
107 return NULL;
108}
109
110