MME2 changes - Propped commits from openmme/paging branch. Added scripts
for code gen
Change-Id: Ie55032217232214ac8544ca76ea34335205329e4
diff --git a/src/s11/Makefile b/src/s11/Makefile
new file mode 100644
index 0000000..c7a11c4
--- /dev/null
+++ b/src/s11/Makefile
@@ -0,0 +1,72 @@
+#
+# Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+# Copyright (c) 2017 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+include ../../Makefile.common
+
+LIB_PATH +=-L../common/
+
+SRCDIR := .
+TARGET := $(BINDIR)/s11-app
+S11_JSON = s11.json
+
+SRCEXT := c
+
+SOURCES := $(shell find $(SRCDIR) -type f -name '*.$(SRCEXT)')
+
+OBJECTS := $(patsubst $(SRCDIR)/%,$(OBJDIR)/s11/%,$(SOURCES:.$(SRCEXT)=.o))
+
+CFLAGS += -Wall
+
+ifeq ($(DEBUG),true)
+ CFLAGS += -g
+endif
+
+ifeq ($(DEBUG),false)
+ CFLAGS += -O3
+endif
+
+LIBS := \
+ -lpthread \
+ -lthreadpool \
+ -lsctp \
+ -lgtpV2Codec \
+ -lcmnUtils \
+ -linterface \
+ -llog \
+ -ljson
+
+$(TARGET): $(OBJECTS)
+ @echo " Linking..."
+ @mkdir -p $(BINDIR)
+ g++ $(LFLAGS) $^ -o $(TARGET) $(LIB_PATH) $(LIBS)
+
+$(OBJDIR)/s11/%.o: $(SRCDIR)/%.$(SRCEXT)
+ @mkdir -p $(OBJDIR)/s11/handlers
+ $(CC) $(CFLAGS) $(INC_DIRS) -c -o $@ $<
+
+all:$(TARGET)
+
+clean:
+ @echo " Cleaning...";
+ @rm -rf $(OBJDIR)/s11 $(TARGET)
+
+install:
+ @mkdir -p $(TARGET_DIR)/bin/
+ -@cp $(TARGET) $(TARGET_DIR)/bin/
+ -@cp conf/$(S11_JSON) $(TARGET_DIR)/conf/
+
+.PHONY: clean
+
diff --git a/src/s11/conf/s11.json b/src/s11/conf/s11.json
new file mode 100644
index 0000000..48ecf11
--- /dev/null
+++ b/src/s11/conf/s11.json
@@ -0,0 +1,37 @@
+{
+ "mme": {
+ "ip_addr": "192.168.1.55",
+ "name": "vmmestandalone",
+ "group_id": 1,
+ "code": 1,
+ "__comment__": "Here is comment",
+ "mcc": {
+ "dig1": 2,
+ "dig2": 0,
+ "dig3": 8
+ },
+ "mnc": {
+ "dig1": 0,
+ "dig2": 1,
+ "dig3": -1
+ }
+ },
+ "s1ap": {
+ "s1ap_local_addr": "192.168.1.55",
+ "sctp_port": 36412,
+ "enb_addr": "127.0.0.1",
+ "enb_port": 5003,
+ "egtp_default_hostname": "sutlej.ccin.ccpu.com"
+ },
+ "s11": {
+ "egtp_local_addr": "192.168.1.55",
+ "egtp_default_port": 2123,
+ "sgw_addr": "127.0.0.1",
+ "pgw_addr": "192.168.1.105"
+ },
+ "s6a": {
+ "host_type": "freediameter",
+ "host": "hss.openair4G.eur",
+ "realm": "openair4G.eur"
+ }
+}
diff --git a/src/s11/gtpv2c.c b/src/s11/gtpv2c.c
new file mode 100644
index 0000000..7ec3a38
--- /dev/null
+++ b/src/s11/gtpv2c.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <arpa/inet.h>
+#include "gtpv2c.h"
+
+void
+set_gtpv2c_header(struct gtpv2c_header *gtpv2c_tx, uint8_t type, uint32_t teid,
+ uint32_t seq)
+{
+
+ gtpv2c_tx->gtp.message_type = type;
+
+ gtpv2c_tx->gtp.version = GTP_VERSION_GTPV2C;
+ gtpv2c_tx->gtp.piggyback = 0;
+ gtpv2c_tx->gtp.teidFlg = 1;
+ gtpv2c_tx->gtp.spare = 0;
+
+ gtpv2c_tx->teid.has_teid.teid = htonl(teid);
+ gtpv2c_tx->teid.has_teid.seq = htonl(seq) >> 8;
+ gtpv2c_tx->teid.has_teid.spare = 0;
+
+ gtpv2c_tx->gtp.len = htons(8);
+
+ return;
+}
diff --git a/src/s11/handlers/create_session_handler.c b/src/s11/handlers/create_session_handler.c
new file mode 100644
index 0000000..575a8d7
--- /dev/null
+++ b/src/s11/handlers/create_session_handler.c
@@ -0,0 +1,263 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+#include <errno.h>
+
+#include "log.h"
+#include "err_codes.h"
+#include "message_queues.h"
+#include "ipc_api.h"
+#include "msgType.h"
+//#include "stage5_s11_info.h"
+#include "gtpv2c.h"
+#include "gtpv2c_ie.h"
+#include "s11_config.h"
+#include "../../gtpV2Codec/gtpV2StackWrappers.h"
+
+/************************************************************************
+Current file : Stage 5 handler.
+ATTACH stages :
+ Stage 1 : IAM-->[stage1 handler]-->AIR, ULR
+ Stage 2 : AIA, ULA -->[stage2 handler]--> Auth req
+ Stage 3 : Auth resp-->[stage3 handler]-->Sec mode cmd
+ Stage 4 : sec mode resp-->[stage4 handler]-->esm infor req
+--> Stage 5 : esm infor resp-->[stage5 handler]-->create session
+ Stage 6 : create session resp-->[stage6 handler]-->init ctx setup
+ Stage 7 : attach complete-->[stage7 handler]-->modify bearer
+**************************************************************************/
+
+/****Globals and externs ***/
+
+/*S11 CP communication parameters*/
+extern int g_s11_fd;
+extern struct sockaddr_in g_s11_cp_addr;
+extern socklen_t g_s11_serv_size;
+
+extern s11_config g_s11_cfg;
+volatile uint32_t g_s11_sequence = 1;
+
+/****Global and externs end***/
+static char buf[S11_CSREQ_STAGE5_BUF_SIZE];
+
+struct CS_Q_msg *g_csReqInfo;
+
+extern struct GtpV2Stack* gtpStack_gp;
+struct MsgBuffer* csReqMsgBuf_p = NULL;
+
+void
+bswap8_array(uint8_t *src, uint8_t *dest, uint32_t len)
+{
+ for (uint32_t i=0; i<len; i++)
+ dest[i] = ((src[i] & 0x0F)<<4 | (src[i] & 0xF0)>>4);
+
+ return;
+}
+uint32_t
+convert_imsi_to_digits_array(uint8_t *src, uint8_t *dest, uint32_t len)
+{
+ uint8_t msb_digit = 0;
+ uint8_t lsb_digit = 0;
+ uint8_t num_of_digits = 0;
+
+ for(uint32_t i = 0; i < len; i++)
+ {
+ lsb_digit = ((src[i] & 0xF0) >> 4);
+ dest[(2*i) + 1] = lsb_digit;
+
+ msb_digit = (src[i] & 0x0F);
+ dest[2*i] = msb_digit;
+
+ if (lsb_digit != 0x0F)
+ num_of_digits = num_of_digits + 2;
+ else
+ num_of_digits++;
+ }
+
+ return num_of_digits;
+}
+
+/**
+* Stage specific message processing.
+*/
+static int
+create_session_processing(struct CS_Q_msg * g_csReqInfo)
+{
+ GtpV2MessageHeader gtpHeader;
+ gtpHeader.msgType = GTP_CREATE_SESSION_REQ;
+ gtpHeader.sequenceNumber = g_s11_sequence;
+ gtpHeader.teidPresent = true;
+ gtpHeader.teid = g_csReqInfo->ue_idx;
+
+ g_s11_sequence++;
+
+ log_msg(LOG_INFO,"In create session handler->ue_idx:%d\n",g_csReqInfo->ue_idx);
+
+ CreateSessionRequestMsgData msgData;
+ memset(&msgData, 0, sizeof(msgData));
+
+ msgData.imsiIePresent = true;
+ memset(msgData.imsi.imsiValue.digits, 0x0f, 16);
+
+
+ uint8_t imsi_len =
+ convert_imsi_to_digits_array(g_csReqInfo->IMSI,
+ msgData.imsi.imsiValue.digits,
+ BINARY_IMSI_LEN);
+
+ msgData.imsi.imsiValue.length = imsi_len;
+ log_msg(LOG_INFO, "IMSI Len: %d\n", imsi_len);
+
+ msgData.msisdnIePresent = true;
+ msgData.msisdn.msisdnValue.length = 10;
+ for (uint8_t i = 1; i <= 5; i++)
+ {
+ msgData.msisdn.msisdnValue.digits[2*(i-1)] = (g_csReqInfo->MSISDN[i-1] & 0x0F);
+ msgData.msisdn.msisdnValue.digits[(2*i) - 1] = ((g_csReqInfo->MSISDN[i-1] & 0xF0) >> 4);
+ }
+
+ struct TAI *tai = &(g_csReqInfo->tai);
+ struct CGI *cgi = &(g_csReqInfo->utran_cgi);
+
+ msgData.userLocationInformationIePresent = true;
+ msgData.userLocationInformation.taipresent = true;
+ msgData.userLocationInformation.ecgipresent = true;
+
+ msgData.userLocationInformation.tai.trackingAreaCode = ntohs(tai->tac);
+ msgData.userLocationInformation.tai.mccDigit1 = tai->plmn_id.idx[0] & 0x0F;
+ msgData.userLocationInformation.tai.mccDigit2 = (tai->plmn_id.idx[0] & 0xF0) >> 4;
+ msgData.userLocationInformation.tai.mccDigit3 = tai->plmn_id.idx[1] & 0x0F;
+ msgData.userLocationInformation.tai.mncDigit1 = tai->plmn_id.idx[2] & 0x0F;
+ msgData.userLocationInformation.tai.mncDigit2 = (tai->plmn_id.idx[2] & 0xF0) >> 4;
+ msgData.userLocationInformation.tai.mncDigit3 = (tai->plmn_id.idx[1] & 0xF0) >> 4;
+
+ msgData.userLocationInformation.ecgi.eUtranCellId = ntohl(cgi->cell_id);
+ msgData.userLocationInformation.ecgi.mccDigit1 = cgi->plmn_id.idx[0] & 0x0F;
+ msgData.userLocationInformation.ecgi.mccDigit2 = (cgi->plmn_id.idx[0] & 0xF0) >> 4;
+ msgData.userLocationInformation.ecgi.mccDigit3 = cgi->plmn_id.idx[1] & 0x0F;
+ msgData.userLocationInformation.ecgi.mncDigit1 = cgi->plmn_id.idx[2] & 0x0F;
+ msgData.userLocationInformation.ecgi.mncDigit2 = (cgi->plmn_id.idx[2] & 0xF0) >> 4;
+ msgData.userLocationInformation.ecgi.mncDigit3 = (cgi->plmn_id.idx[1] & 0xF0) >> 4;
+
+ msgData.servingNetworkIePresent = true;
+ msgData.servingNetwork.mccDigit1 = tai->plmn_id.idx[0] & 0x0F;
+ msgData.servingNetwork.mccDigit2 = (tai->plmn_id.idx[0] & 0xF0) >> 4;
+ msgData.servingNetwork.mccDigit3 = tai->plmn_id.idx[1] & 0x0F;
+ msgData.servingNetwork.mncDigit1 = tai->plmn_id.idx[2] & 0x0F;
+ msgData.servingNetwork.mncDigit2 = (tai->plmn_id.idx[2] & 0xF0) >> 4;
+ msgData.servingNetwork.mncDigit3 = (tai->plmn_id.idx[1] & 0xF0) >> 4;
+
+ msgData.ratType.ratType = 6;
+
+ msgData.indicationFlagsIePresent = true;
+ msgData.indicationFlags.iDFI = true;
+ msgData.indicationFlags.iMSV = true;
+
+ msgData.senderFTeidForControlPlane.ipv4present = true;
+ msgData.senderFTeidForControlPlane.interfaceType = 10;
+ msgData.senderFTeidForControlPlane.ipV4Address.ipValue = g_s11_cfg.local_egtp_ip;
+ msgData.senderFTeidForControlPlane.teidGreKey = g_csReqInfo->ue_idx;
+
+ msgData.pgwS5S8AddressForControlPlaneOrPmipIePresent = true;
+ msgData.pgwS5S8AddressForControlPlaneOrPmip.ipv4present = true;
+ msgData.pgwS5S8AddressForControlPlaneOrPmip.interfaceType = 7;
+ msgData.pgwS5S8AddressForControlPlaneOrPmip.ipV4Address.ipValue = g_s11_cfg.pgw_ip;
+
+ msgData.accessPointName.apnValue.count = g_csReqInfo->apn.len;
+ memcpy(msgData.accessPointName.apnValue.values, g_csReqInfo->apn.val, g_csReqInfo->apn.len);
+
+ msgData.selectionModeIePresent = true;
+ msgData.selectionMode.selectionMode = 1;
+
+ msgData.pdnTypeIePresent = true;
+ msgData.pdnType.pdnType = 1;
+
+ msgData.pdnAddressAllocationIePresent = true;
+ msgData.pdnAddressAllocation.pdnType = 1;
+ msgData.pdnAddressAllocation.ipV4Address.ipValue = 0;
+
+ msgData.maximumApnRestrictionIePresent = true;
+ msgData.maximumApnRestriction.restrictionValue = 0;
+
+ /* Bearer Context */
+ msgData.bearerContextsToBeCreatedCount = 1;
+ msgData.bearerContextsToBeCreated[0].epsBearerId.epsBearerId = 5;
+
+ msgData.bearerContextsToBeCreated[0].bearerLevelQos.pci = 1;
+ msgData.bearerContextsToBeCreated[0].bearerLevelQos.pl = 11;
+ msgData.bearerContextsToBeCreated[0].bearerLevelQos.pvi = 0;
+ msgData.bearerContextsToBeCreated[0].bearerLevelQos.qci = 9;
+
+ uint32_t mbr_uplink = htonl(MBR_UPLINK);
+ uint32_t mbr_downlink = htonl(MBR_DOWNLINK);
+
+ msgData.bearerContextsToBeCreated[0].bearerLevelQos.maxBitRateUl.count = 5;
+ msgData.bearerContextsToBeCreated[0].bearerLevelQos.maxBitRateDl.count = 5;
+ memcpy(&msgData.bearerContextsToBeCreated[0].bearerLevelQos.maxBitRateUl.values, &mbr_uplink, sizeof(mbr_uplink));
+ memcpy(&msgData.bearerContextsToBeCreated[0].bearerLevelQos.maxBitRateDl.values, &mbr_downlink, sizeof(mbr_downlink));
+ msgData.bearerContextsToBeCreated[0].bearerLevelQos.guraranteedBitRateUl.count = 5;
+ msgData.bearerContextsToBeCreated[0].bearerLevelQos.guaranteedBitRateDl.count = 5;
+
+ msgData.aggregateMaximumBitRateIePresent = true;
+ msgData.aggregateMaximumBitRate.maxMbrUplink = g_csReqInfo->max_requested_bw_ul;
+ msgData.aggregateMaximumBitRate.maxMbrDownlink = g_csReqInfo->max_requested_bw_dl;
+
+ bool rc = GtpV2Stack_buildGtpV2Message(gtpStack_gp, csReqMsgBuf_p, >pHeader, &msgData);
+ if (rc == false)
+ {
+ log_msg(LOG_ERROR, "Failed to encode create session request\n");
+ return E_FAIL;
+ }
+
+ log_msg(LOG_INFO, "send %d bytes.\n",MsgBuffer_getBufLen(csReqMsgBuf_p));
+
+ int res = sendto (
+ g_s11_fd,
+ MsgBuffer_getDataPointer(csReqMsgBuf_p),
+ MsgBuffer_getBufLen(csReqMsgBuf_p), 0,
+ (struct sockaddr*)&g_s11_cp_addr,
+ g_s11_serv_size);
+ if (res < 0) {
+ log_msg(LOG_ERROR,"Error in sendto in detach stage 3 post to next\n");
+ }
+
+ log_msg(LOG_INFO,"%d bytes sent. Err : %d, %s\n",res,errno,
+ strerror(errno));
+
+ MsgBuffer_reset(csReqMsgBuf_p);
+
+ return SUCCESS;
+}
+
+/**
+* Thread function for stage.
+*/
+void*
+create_session_handler(void *data)
+{
+ log_msg(LOG_INFO, "Create Session Request handler\n");
+
+ create_session_processing((struct CS_Q_msg *) data);
+
+ return NULL;
+}
diff --git a/src/s11/handlers/ddn_ack_handler.c b/src/s11/handlers/ddn_ack_handler.c
new file mode 100644
index 0000000..73a459a
--- /dev/null
+++ b/src/s11/handlers/ddn_ack_handler.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+
+#include "log.h"
+#include "err_codes.h"
+#include "message_queues.h"
+#include "ipc_api.h"
+#include "gtpv2c.h"
+#include "gtpv2c_ie.h"
+#include "msgType.h"
+#include "../../gtpV2Codec/gtpV2StackWrappers.h"
+
+
+/****Globals and externs ***/
+
+/*S11 CP communication parameters*/
+extern int g_s11_fd;
+extern struct sockaddr_in g_s11_cp_addr;
+extern socklen_t g_s11_serv_size;
+extern volatile uint32_t g_s11_sequence;
+static char buf[S11_DDN_ACK_BUF_SIZE];
+
+struct thread_pool *g_tpool;
+
+extern struct GtpV2Stack* gtpStack_gp;
+extern volatile uint32_t g_s11_sequence;
+
+struct MsgBuffer* ddnAckMsgBuf_p = NULL;
+/****Global and externs end***/
+
+/**
+* Stage specific message processing.
+*/
+static int
+ddn_ack_processing(struct DDN_ACK_Q_msg *ddn_ack_msg)
+{
+ GtpV2MessageHeader gtpHeader;
+ gtpHeader.msgType = 177;
+ gtpHeader.sequenceNumber = ddn_ack_msg->seq_no;
+ gtpHeader.teidPresent = true;
+ gtpHeader.teid = ddn_ack_msg->ue_idx;
+
+ DownlinkDataNotificationAcknowledgeMsgData msgData;
+ memset(&msgData, 0, sizeof(DownlinkDataNotificationAcknowledgeMsgData));
+
+ msgData.cause.causeValue = ddn_ack_msg->cause;
+
+
+ GtpV2Stack_buildGtpV2Message(gtpStack_gp, ddnAckMsgBuf_p, >pHeader, &msgData);
+ g_s11_sequence++;
+
+ sendto(g_s11_fd,
+ MsgBuffer_getDataPointer(ddnAckMsgBuf_p),
+ MsgBuffer_getBufLen(ddnAckMsgBuf_p), 0,
+ (struct sockaddr*)&g_s11_cp_addr, g_s11_serv_size);
+
+ log_msg(LOG_INFO, "DDN Ack Sent, len - %d bytes.\n", MsgBuffer_getBufLen(ddnAckMsgBuf_p));
+ MsgBuffer_reset(ddnAckMsgBuf_p);
+ return SUCCESS;
+}
+
+
+/**
+* Thread function for stage.
+*/
+void*
+ddn_ack_handler(void *data)
+{
+ log_msg(LOG_INFO, "DDN Ack handler initialized\n");
+ ddn_ack_processing((struct DDN_ACK_Q_msg *)data);
+ return NULL;
+}
+
diff --git a/src/s11/handlers/delete_session_handler.c b/src/s11/handlers/delete_session_handler.c
new file mode 100644
index 0000000..b7758b3
--- /dev/null
+++ b/src/s11/handlers/delete_session_handler.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+
+#include "log.h"
+#include "err_codes.h"
+#include "message_queues.h"
+#include "ipc_api.h"
+#include "gtpv2c.h"
+#include "gtpv2c_ie.h"
+#include "msgType.h"
+#include "../../gtpV2Codec/gtpV2StackWrappers.h"
+/************************************************************************
+Current file : Stage 1 handler.
+ATTACH stages :
+ Stage 1 : detach request -->delete session
+**************************************************************************/
+
+/****Globals and externs ***/
+
+/*S11 CP communication parameters*/
+extern int g_s11_fd;
+extern struct sockaddr_in g_s11_cp_addr;
+extern socklen_t g_s11_serv_size;
+extern volatile uint32_t g_s11_sequence;
+static char buf[S11_DTCHREQ_STAGE1_BUF_SIZE];
+
+struct thread_pool *g_tpool;
+
+extern struct GtpV2Stack* gtpStack_gp;
+extern volatile uint32_t g_s11_sequence;
+
+struct MsgBuffer* dsReqMsgBuf_p = NULL;
+/****Global and externs end***/
+
+/**
+* Stage specific message processing.
+*/
+static int
+delete_session_processing(struct DS_Q_msg *ds_msg)
+{
+ GtpV2MessageHeader gtpHeader;
+ gtpHeader.msgType = GTP_DELETE_SESSION_REQ;
+ gtpHeader.sequenceNumber = g_s11_sequence;
+ gtpHeader.teidPresent = true;
+ gtpHeader.teid = ds_msg->s11_sgw_c_fteid.header.teid_gre;
+
+ DeleteSessionRequestMsgData msgData;
+ memset(&msgData, 0, sizeof(DeleteSessionRequestMsgData));
+
+ msgData.indicationFlagsIePresent = true;
+ msgData.indicationFlags.iOI = true;
+
+ msgData.linkedEpsBearerIdIePresent = true;
+ msgData.linkedEpsBearerId.epsBearerId = ds_msg->bearer_id;
+
+ GtpV2Stack_buildGtpV2Message(gtpStack_gp, dsReqMsgBuf_p, >pHeader, &msgData);
+ g_s11_sequence++;
+
+ sendto(g_s11_fd,
+ MsgBuffer_getDataPointer(dsReqMsgBuf_p),
+ MsgBuffer_getBufLen(dsReqMsgBuf_p), 0,
+ (struct sockaddr*)&g_s11_cp_addr, g_s11_serv_size);
+ log_msg(LOG_INFO, "Send delete session request\n");
+
+ MsgBuffer_reset(dsReqMsgBuf_p);
+
+ return SUCCESS;
+}
+
+
+/**
+* Thread function for stage.
+*/
+void*
+delete_session_handler(void *data)
+{
+ log_msg(LOG_INFO, "Delete session handler initialized\n");
+
+ delete_session_processing((struct DS_Q_msg *)data);
+ return NULL;
+}
+
diff --git a/src/s11/handlers/modify_bearer_handler.c b/src/s11/handlers/modify_bearer_handler.c
new file mode 100644
index 0000000..978ae8a
--- /dev/null
+++ b/src/s11/handlers/modify_bearer_handler.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <string.h>
+
+#include "log.h"
+#include "err_codes.h"
+#include "message_queues.h"
+#include "ipc_api.h"
+#include "s11_structs.h"
+#include "msgType.h"
+//#include "stage7_info.h"
+#include "gtpv2c.h"
+#include "gtpv2c_ie.h"
+#include "../../gtpV2Codec/gtpV2StackWrappers.h"
+
+/************************************************************************
+Current file : Stage 7 handler. To listen MB from mme-app and fwd to CP
+ATTACH stages :
+ Stage 1 : IAM-->[stage1 handler]-->AIR, ULR
+ Stage 2 : AIA, ULA -->[stage2 handler]--> Auth req
+ Stage 3 : Auth resp-->[stage3 handler]-->Sec mode cmd
+ Stage 4 : sec mode resp-->[stage4 handler]-->esm infor req
+ Stage 5 : esm infor resp-->[stage5 handler]-->create session
+ Stage 6 : create session resp-->[stage6 handler]-->init ctx setup
+--> Stage 7 : attach complete-->[stage7 handler]-->modify bearer
+**************************************************************************/
+
+/****Globals and externs ***/
+
+extern int g_s11_fd;
+extern struct sockaddr_in g_s11_cp_addr;
+extern socklen_t g_s11_serv_size;
+/*TODO: S11 protocol sequence number - need to make it atomic. multiple thread to access this*/
+extern volatile uint32_t g_s11_sequence;
+static char buf[S11_MBREQ_STAGE7_BUF_SIZE];
+
+/*TODO: S11 protocol sequence number - need to make it atomic. multiple thread to access this*/
+extern volatile uint32_t g_s11_sequence;
+
+struct MsgBuffer* mbReqMsgBuf_p = NULL;
+extern struct GtpV2Stack* gtpStack_gp;
+/****Global and externs end***/
+/**
+* Stage specific message processing.
+*/
+static int
+modify_bearer_processing(struct MB_Q_msg *mb_msg)
+{
+ GtpV2MessageHeader gtpHeader;
+ gtpHeader.msgType = GTP_MODIFY_BEARER_REQ;
+ gtpHeader.sequenceNumber = g_s11_sequence;
+ gtpHeader.teidPresent = true;
+ gtpHeader.teid = mb_msg->s11_sgw_c_fteid.header.teid_gre;
+
+ g_s11_sequence++;
+
+ ModifyBearerRequestMsgData msgData;
+ memset(&msgData, 0, sizeof(msgData));
+ msgData.bearerContextsToBeModifiedCount = 1;
+ msgData.bearerContextsToBeModified[0].epsBearerId.epsBearerId = 5;
+ msgData.bearerContextsToBeModified[0].s1EnodebFTeidIePresent = true;
+ msgData.bearerContextsToBeModified[0].s1EnodebFTeid.ipv4present = true;
+ msgData.bearerContextsToBeModified[0].s1EnodebFTeid.interfaceType = mb_msg->s1u_enb_fteid.header.iface_type;
+ msgData.bearerContextsToBeModified[0].s1EnodebFTeid.teidGreKey = mb_msg->s1u_enb_fteid.header.teid_gre;
+ msgData.bearerContextsToBeModified[0].s1EnodebFTeid.ipV4Address.ipValue = mb_msg->s1u_enb_fteid.ip.ipv4.s_addr;
+
+ GtpV2Stack_buildGtpV2Message(gtpStack_gp, mbReqMsgBuf_p, >pHeader, &msgData);
+ sendto(g_s11_fd,
+ MsgBuffer_getDataPointer(mbReqMsgBuf_p),
+ MsgBuffer_getBufLen(mbReqMsgBuf_p), 0,
+ (struct sockaddr*)&g_s11_cp_addr,
+ g_s11_serv_size);
+ //TODO " error chk, eagain etc?
+ log_msg(LOG_INFO, "Modify beader send, len - %d bytes.\n", MsgBuffer_getBufLen(mbReqMsgBuf_p));
+
+ MsgBuffer_reset(mbReqMsgBuf_p);
+
+ return SUCCESS;
+}
+
+/**
+* Thread function for stage.
+*/
+void*
+modify_bearer_handler(void *data)
+{
+ log_msg(LOG_INFO, "Modify bearer handler initialized\n");
+
+ modify_bearer_processing((struct MB_Q_msg *)data);
+
+ return NULL;
+}
diff --git a/src/s11/handlers/release_bearer_handler.c b/src/s11/handlers/release_bearer_handler.c
new file mode 100644
index 0000000..e18cc37
--- /dev/null
+++ b/src/s11/handlers/release_bearer_handler.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <string.h>
+
+#include "log.h"
+#include "err_codes.h"
+#include "message_queues.h"
+#include "ipc_api.h"
+#include "s11_structs.h"
+#include "msgType.h"
+//#include "stage7_info.h"
+#include "gtpv2c.h"
+#include "gtpv2c_ie.h"
+#include "../../gtpV2Codec/gtpV2StackWrappers.h"
+
+/************************************************************************
+Current file : Stage 7 handler. To listen MB from mme-app and fwd to CP
+ATTACH stages :
+ Stage 1 : IAM-->[stage1 handler]-->AIR, ULR
+ Stage 2 : AIA, ULA -->[stage2 handler]--> Auth req
+ Stage 3 : Auth resp-->[stage3 handler]-->Sec mode cmd
+ Stage 4 : sec mode resp-->[stage4 handler]-->esm infor req
+ Stage 5 : esm infor resp-->[stage5 handler]-->create session
+ Stage 6 : create session resp-->[stage6 handler]-->init ctx setup
+--> Stage 7 : attach complete-->[stage7 handler]-->modify bearer
+**************************************************************************/
+
+/****Globals and externs ***/
+
+
+extern int g_s11_fd;
+extern struct sockaddr_in g_s11_cp_addr;
+extern socklen_t g_s11_serv_size;
+/*TODO: S11 protocol sequence number - need to make it atomic. multiple thread to access this*/
+extern volatile uint32_t g_s11_sequence;
+
+struct MsgBuffer* rbReqMsgBuf_p = NULL;
+extern struct GtpV2Stack* gtpStack_gp;
+
+
+/****Global and externs end***/
+/**
+* Stage specific message processing.
+*/
+static int
+release_bearer_processing(struct RB_Q_msg *rb_msg)
+{
+ GtpV2MessageHeader gtpHeader;
+ gtpHeader.msgType = GTP_RELEASE_BEARER_REQ;
+ gtpHeader.sequenceNumber = g_s11_sequence;
+ gtpHeader.teidPresent = true;
+ gtpHeader.teid = rb_msg->s11_sgw_c_fteid.header.teid_gre;
+
+ g_s11_sequence++;
+
+ ReleaseAccessBearersRequestMsgData msgData;
+ memset(&msgData, 0, sizeof(msgData));
+
+ msgData.indicationFlagsIePresent = true;
+ msgData.indicationFlags.iOI = true;
+
+ GtpV2Stack_buildGtpV2Message(gtpStack_gp, rbReqMsgBuf_p, >pHeader, &msgData);
+
+ sendto(g_s11_fd,
+ MsgBuffer_getDataPointer(rbReqMsgBuf_p),
+ MsgBuffer_getBufLen(rbReqMsgBuf_p), 0,
+ (struct sockaddr*)&g_s11_cp_addr,
+ g_s11_serv_size);
+ //TODO " error chk, eagain etc?
+ log_msg(LOG_INFO, "Release Bearer sent, len - %d bytes.\n", MsgBuffer_getBufLen(rbReqMsgBuf_p));
+
+ MsgBuffer_reset(rbReqMsgBuf_p);
+
+ return SUCCESS;
+
+}
+
+
+/**
+* Thread function for stage.
+*/
+void*
+release_bearer_handler(void *data)
+{
+
+ log_msg(LOG_INFO, "Release bearer handler initialized\n");
+
+ release_bearer_processing((struct RB_Q_msg *)data);
+
+ return NULL;
+}
+
+
diff --git a/src/s11/handlers/s11_CS_resp_handler.c b/src/s11/handlers/s11_CS_resp_handler.c
new file mode 100644
index 0000000..14c6af7
--- /dev/null
+++ b/src/s11/handlers/s11_CS_resp_handler.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+
+#include "err_codes.h"
+#include "options.h"
+#include "ipc_api.h"
+#include "message_queues.h"
+#include "s11.h"
+#include "s11_config.h"
+#include "msgType.h"
+//#include "stage6_info.h"
+#include "../../gtpV2Codec/gtpV2StackWrappers.h"
+
+/*Globals and externs*/
+extern int g_resp_fd;
+extern struct GtpV2Stack* gtpStack_gp;
+/*End : globals and externs*/
+
+
+int
+s11_CS_resp_handler(MsgBuffer* message, GtpV2MessageHeader* hdr)
+{
+
+ struct gtp_incoming_msg_data_t csr_info;
+ /*****Message structure***
+ */
+
+ /*Check whether has teid flag is set. Also check whether this check is needed for CSR.*/
+ csr_info.ue_idx = hdr->teid;
+ csr_info.msg_type = create_session_response;
+
+ CreateSessionResponseMsgData msgData;
+ memset(&msgData, 0, sizeof(CreateSessionResponseMsgData));
+
+ bool rc = GtpV2Stack_decodeMessage(gtpStack_gp, hdr, message, &msgData);
+ if(rc == false)
+ {
+ log_msg(LOG_ERROR, "s11_CS_resp_handler: "
+ "Failed to decode Create Session Response Msg %d\n",
+ hdr->teid);
+ return E_PARSING_FAILED;
+ }
+
+ csr_info.msg_data.csr_Q_msg_m.s11_sgw_fteid.header.iface_type = 11;
+ csr_info.msg_data.csr_Q_msg_m.s11_sgw_fteid.header.teid_gre = msgData.senderFTeidForControlPlane.teidGreKey;
+ csr_info.msg_data.csr_Q_msg_m.s11_sgw_fteid.header.v4 = 1;
+ csr_info.msg_data.csr_Q_msg_m.s11_sgw_fteid.ip.ipv4.s_addr = msgData.senderFTeidForControlPlane.ipV4Address.ipValue;
+
+ csr_info.msg_data.csr_Q_msg_m.s5s8_pgwc_fteid.header.iface_type = 7;
+ csr_info.msg_data.csr_Q_msg_m.s5s8_pgwc_fteid.header.teid_gre = msgData.pgwS5S8S2bFTeid.teidGreKey;
+ csr_info.msg_data.csr_Q_msg_m.s5s8_pgwc_fteid.header.v4 = 1;
+ csr_info.msg_data.csr_Q_msg_m.s5s8_pgwc_fteid.ip.ipv4.s_addr = msgData.pgwS5S8S2bFTeid.ipV4Address.ipValue;
+
+ csr_info.msg_data.csr_Q_msg_m.s1u_sgw_fteid.header.iface_type = 1;
+ csr_info.msg_data.csr_Q_msg_m.s1u_sgw_fteid.header.teid_gre = msgData.bearerContextsCreated[0].s1USgwFTeid.teidGreKey;
+ csr_info.msg_data.csr_Q_msg_m.s1u_sgw_fteid.header.v4 = 1;
+ csr_info.msg_data.csr_Q_msg_m.s1u_sgw_fteid.ip.ipv4.s_addr = msgData.bearerContextsCreated[0].s1USgwFTeid.ipV4Address.ipValue;
+
+ csr_info.msg_data.csr_Q_msg_m.s5s8_pgwu_fteid.header.iface_type = 5;
+ csr_info.msg_data.csr_Q_msg_m.s5s8_pgwu_fteid.header.teid_gre = msgData.bearerContextsCreated[0].s5S8UPgwFTeid.teidGreKey;
+ csr_info.msg_data.csr_Q_msg_m.s5s8_pgwu_fteid.header.v4 = 1;
+ csr_info.msg_data.csr_Q_msg_m.s5s8_pgwu_fteid.ip.ipv4.s_addr = msgData.bearerContextsCreated[0].s5S8UPgwFTeid.ipV4Address.ipValue;
+
+ csr_info.msg_data.csr_Q_msg_m.pdn_addr.pdn_type = 1;
+ csr_info.msg_data.csr_Q_msg_m.pdn_addr.ip_type.ipv4.s_addr = msgData.pdnAddressAllocation.ipV4Address.ipValue;
+
+
+ csr_info.destInstAddr = htonl(mmeAppInstanceNum_c);
+ csr_info.srcInstAddr = htonl(s11AppInstanceNum_c);
+
+ /*Send CS response msg*/
+ send_tipc_message(g_resp_fd, mmeAppInstanceNum_c, (char *)&csr_info, GTP_READ_MSG_BUF_SIZE);
+ log_msg(LOG_INFO, "Send CS resp to mme-app stage6.\n");
+
+ return SUCCESS;
+}
diff --git a/src/s11/handlers/s11_DDN_handler.c b/src/s11/handlers/s11_DDN_handler.c
new file mode 100644
index 0000000..ac10f67
--- /dev/null
+++ b/src/s11/handlers/s11_DDN_handler.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+
+#include "err_codes.h"
+#include "options.h"
+#include "ipc_api.h"
+#include "message_queues.h"
+#include "s11.h"
+#include "s11_config.h"
+#include "msgType.h"
+//#include "detach_stage2_info.h"
+#include "../../gtpV2Codec/gtpV2StackWrappers.h"
+/*Globals and externs*/
+extern int g_resp_fd;
+extern struct GtpV2Stack* gtpStack_gp;
+/*End : globals and externs*/
+
+
+int
+s11_DDN_handler(MsgBuffer* message, GtpV2MessageHeader* hdr)
+{
+
+
+ struct gtp_incoming_msg_data_t ddn_info;
+ ddn_info.msg_type = downlink_data_notification;
+ ddn_info.ue_idx = hdr->teid;
+ ddn_info.msg_data.ddn_Q_msg_m.seq_no = hdr->sequenceNumber;
+
+
+ DownlinkDataNotificationMsgData msgData;
+ memset(&msgData, 0, sizeof(DownlinkDataNotificationMsgData));
+
+ bool rc = GtpV2Stack_decodeMessage(gtpStack_gp, hdr, message, &msgData);
+ if(rc == false)
+ {
+
+ log_msg(LOG_ERROR, "s11_Ddn_handler: "
+ "Failed to decode ddn Msg %d\n",
+ hdr->teid);
+ return E_PARSING_FAILED;
+ }
+ /*****Message structure****/
+ log_msg(LOG_INFO, "Parse S11 Ddn message\n");
+
+ //TODO : check cause for the result verification
+
+ ddn_info.msg_data.ddn_Q_msg_m.arp.prioLevel = msgData.allocationRetentionPriority.pl;
+ ddn_info.msg_data.ddn_Q_msg_m.arp.preEmptionCapab = msgData.allocationRetentionPriority.pci;
+ ddn_info.msg_data.ddn_Q_msg_m.arp.preEmptionVulnebility = msgData.allocationRetentionPriority.pvi;
+ ddn_info.msg_data.ddn_Q_msg_m.cause = msgData.cause.causeValue;
+ ddn_info.msg_data.ddn_Q_msg_m.eps_bearer_id = msgData.epsBearerId.epsBearerId;
+
+ ddn_info.destInstAddr = htonl(mmeAppInstanceNum_c);
+ ddn_info.srcInstAddr = htonl(s11AppInstanceNum_c);
+
+ /*Send DDN msg*/
+ send_tipc_message(g_resp_fd, mmeAppInstanceNum_c, (char *)&ddn_info, GTP_READ_MSG_BUF_SIZE);
+
+ log_msg(LOG_INFO, "Send ddn to mme-app\n");
+
+
+ return SUCCESS;
+}
diff --git a/src/s11/handlers/s11_DS_resp_handler.c b/src/s11/handlers/s11_DS_resp_handler.c
new file mode 100644
index 0000000..abb6d53
--- /dev/null
+++ b/src/s11/handlers/s11_DS_resp_handler.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+
+#include "err_codes.h"
+#include "options.h"
+#include "ipc_api.h"
+#include "message_queues.h"
+#include "s11.h"
+#include "s11_config.h"
+#include "msgType.h"
+//#include "detach_stage2_info.h"
+#include "../../gtpV2Codec/gtpV2StackWrappers.h"
+/*Globals and externs*/
+extern int g_resp_fd;
+
+/*End : globals and externs*/
+
+int
+s11_DS_resp_handler(MsgBuffer* message, GtpV2MessageHeader* hdr)
+{
+
+
+ struct gtp_incoming_msg_data_t dsr_info;
+ dsr_info.msg_type = delete_session_response;
+
+ /*****Message structure****/
+ log_msg(LOG_INFO, "Parse S11 DS resp message\n");
+
+ //TODO : check cause for the result verification
+
+ /*Check whether has teid flag is set.
+ * Also check whether this check is needed for DSR.
+ * */
+ dsr_info.ue_idx = hdr->teid;
+
+ dsr_info.destInstAddr = htonl(mmeAppInstanceNum_c);
+ dsr_info.srcInstAddr = htonl(s11AppInstanceNum_c);
+
+ /*Send CS response msg*/
+ send_tipc_message(g_resp_fd, mmeAppInstanceNum_c, (char *)&dsr_info,
+ GTP_READ_MSG_BUF_SIZE);
+ log_msg(LOG_INFO, "Send DS resp to mme-app stage8.\n");
+
+ return SUCCESS;
+}
diff --git a/src/s11/handlers/s11_MB_resp_handler.c b/src/s11/handlers/s11_MB_resp_handler.c
new file mode 100644
index 0000000..5c25327
--- /dev/null
+++ b/src/s11/handlers/s11_MB_resp_handler.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+
+#include "err_codes.h"
+#include "options.h"
+#include "ipc_api.h"
+#include "message_queues.h"
+#include "s11.h"
+#include "s11_config.h"
+#include "msgType.h"
+//#include "stage8_info.h"
+#include "../../gtpV2Codec/gtpV2StackWrappers.h"
+/*Globals and externs*/
+extern int g_resp_fd;
+
+/*End : globals and externs*/
+
+int
+s11_MB_resp_handler(MsgBuffer* message, GtpV2MessageHeader* hdr)
+{
+
+ struct gtp_incoming_msg_data_t mbr_info;
+
+ /*****Message structure***
+ */
+ log_msg(LOG_INFO, "Parse S11 MB resp message\n");
+
+ //TODO : check cause foor the result verification
+
+ /*Check whether has teid flag is set. Also check whether this check is needed for CSR.*/
+ mbr_info.ue_idx = hdr->teid;
+ mbr_info.msg_type = modify_bearer_response;
+
+ mbr_info.destInstAddr = htonl(mmeAppInstanceNum_c);
+ mbr_info.srcInstAddr = htonl(s11AppInstanceNum_c);
+ /*Send CS response msg*/
+ send_tipc_message(g_resp_fd, mmeAppInstanceNum_c, (char *)&mbr_info, GTP_READ_MSG_BUF_SIZE);
+ log_msg(LOG_INFO, "Send MB resp to mme-app stage8.\n");
+
+ return SUCCESS;
+}
diff --git a/src/s11/handlers/s11_RB_resp_handler.c b/src/s11/handlers/s11_RB_resp_handler.c
new file mode 100644
index 0000000..d9d7897
--- /dev/null
+++ b/src/s11/handlers/s11_RB_resp_handler.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+
+#include "err_codes.h"
+#include "options.h"
+#include "ipc_api.h"
+#include "message_queues.h"
+#include "s11.h"
+#include "s11_config.h"
+#include "msgType.h"
+//#include "stage8_info.h"
+#include "../../gtpV2Codec/gtpV2StackWrappers.h"
+
+/*Globals and externs*/
+extern int g_resp_fd;
+extern struct GtpV2Stack* gtpStack_gp;
+
+/*End : globals and externs*/
+
+int
+s11_RB_resp_handler(MsgBuffer* message, GtpV2MessageHeader* hdr)
+{
+ struct gtp_incoming_msg_data_t rbr_info;
+
+ /*****Message structure***
+ */
+ log_msg(LOG_INFO, "Parse S11 RB resp message\n");
+
+ //TODO : check cause for the result verification
+
+ rbr_info.ue_idx = hdr->teid;
+ rbr_info.msg_type = release_bearer_response;
+
+ ReleaseAccessBearersResponseMsgData msgData;
+ memset(&msgData, 0, sizeof(ReleaseAccessBearersResponseMsgData));
+
+ bool rc = GtpV2Stack_decodeMessage(gtpStack_gp, hdr, message, &msgData);
+ if(rc == false)
+ {
+ log_msg(LOG_ERROR, "s11_RB_resp_handler: "
+ "Failed to decode Release Access Bearer Response Msg %d\n",
+ hdr->teid);
+ return E_PARSING_FAILED;
+ }
+
+
+ rbr_info.destInstAddr = htonl(mmeAppInstanceNum_c);
+ rbr_info.srcInstAddr = htonl(s11AppInstanceNum_c);
+
+ /*Send CS response msg*/
+ send_tipc_message(g_resp_fd, mmeAppInstanceNum_c, (char *)&rbr_info, GTP_READ_MSG_BUF_SIZE);
+ log_msg(LOG_INFO, "Send RB resp to mme-app stage2.\n");
+
+ return SUCCESS;
+}
diff --git a/src/s11/handlers/s11_msg_delegator.c b/src/s11/handlers/s11_msg_delegator.c
new file mode 100644
index 0000000..fbb0d7b
--- /dev/null
+++ b/src/s11/handlers/s11_msg_delegator.c
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+
+#include "err_codes.h"
+#include "options.h"
+#include "ipc_api.h"
+#include "message_queues.h"
+#include "s11.h"
+#include "s11_config.h"
+#include "s11_structs.h"
+#include "../../gtpV2Codec/gtpV2StackWrappers.h"
+
+extern struct GtpV2Stack* gtpStack_gp;
+int s11_CS_resp_handler(MsgBuffer* message, GtpV2MessageHeader* hdr);
+int s11_MB_resp_handler(MsgBuffer* message, GtpV2MessageHeader* hdr);
+int s11_DS_resp_handler(MsgBuffer* message, GtpV2MessageHeader* hdr);
+int s11_RB_resp_handler(MsgBuffer* message, GtpV2MessageHeader* hdr);
+int s11_DDN_handler(MsgBuffer* message, GtpV2MessageHeader* hdr);
+
+/*
+ Get count of no of IEs in gtpv2c msg
+*/
+static int
+get_IE_cnt(char *msg, int len)
+{
+ int cnt = 0;
+ char *tmp = msg+11;
+ struct s11_IE_header *header = (struct s11_IE_header *)tmp;
+
+ for(; (char *)tmp <= msg + len; ++cnt) {
+ tmp += sizeof(struct s11_IE_header) + ntohs(header->ie_len);
+ header = (struct s11_IE_header*)tmp;
+ }
+ return cnt;
+}
+
+void
+network_cp_fteid(struct fteid *teid, char *data)
+{
+ unsigned int *tmp;
+
+ memcpy(teid, data, sizeof(struct fteid));
+ teid->header.teid_gre = ntohl(teid->header.teid_gre);
+ tmp = (unsigned int*)(data+5);
+ *tmp = ntohl(*tmp);
+ memcpy(&(teid->ip.ipv4), tmp, sizeof(struct in_addr));
+}
+
+int
+parse_bearer_ctx(struct bearer_ctx *bearer, char* data, short len)
+{
+ char no_of_ies = 4;
+ //TODO: count no of IEs
+
+ for(int i=0; i < no_of_ies; ++i) {
+ struct s11_IE_header *header = (struct s11_IE_header*)data;
+ char *value = data + sizeof(struct s11_IE_header);
+
+ switch(header->ie_type){
+ case S11_IE_CAUSE:
+ memcpy(&(bearer->cause), value, sizeof(struct gtp_cause));
+ break;
+
+ case S11_IE_FTEID_C:{
+ #define S1U_SGW_FTEID 1 /*binary 0001*/
+ if((0x0F & (unsigned char)(*value))
+ == S1U_SGW_FTEID) {
+ network_cp_fteid(&bearer->s1u_sgw_teid, value);
+ }
+ else { /*s5s8 pgw_U ftied*/
+ network_cp_fteid(&bearer->s5s8_pgw_u_teid, value);
+ }
+ break;
+ }
+
+ case S11_IE_EPS_BEARER_ID:
+ bearer->eps_bearer_id = (unsigned char)(*value);
+ break;
+
+ default:
+ log_msg(LOG_ERROR, "Unhandled S11 bearer IE: %d\n", header->ie_type);
+ }
+
+ data += ntohs(header->ie_len) + sizeof(struct s11_IE_header); /*goto next IE*/
+ }
+ return SUCCESS;
+}
+
+int
+parse_gtpv2c_IEs(char *msg, int len, struct s11_proto_IE *proto_ies)
+{
+ proto_ies->no_of_ies = get_IE_cnt(msg, len);
+
+ if(0 == proto_ies->no_of_ies) {
+ log_msg(LOG_INFO, "No IEs recvd in message\n");
+ return SUCCESS;
+ }
+ log_msg(LOG_INFO, "No of IEs - %d\n", proto_ies->no_of_ies);
+
+ /*allocated IEs for message*/
+ proto_ies->s11_ies = (struct s11_IE*)calloc(sizeof(struct s11_IE),
+ proto_ies->no_of_ies);
+ msg +=11;
+
+ for(int i=0; i < proto_ies->no_of_ies; ++i) {
+ struct s11_IE *ie = &(proto_ies->s11_ies[i]);
+ char *data = msg + sizeof(struct s11_IE_header);
+
+ memcpy(&(ie->header), msg, sizeof(struct s11_IE_header));
+
+ switch(ie->header.ie_type){
+ case S11_IE_CAUSE:
+ memcpy(&(ie->data.cause), data, sizeof(struct gtp_cause));
+ break;
+
+ case S11_IE_FTEID_C:{
+ #define S11_SGW_C_FTEID 11 /*binary 1011*/
+ if((0x0F & (unsigned char)(*data))
+ == S11_SGW_C_FTEID) {
+ network_cp_fteid(&(ie->data.s11_sgw_fteid), data);
+ }
+ else { /*s5s8 pgw_c ftied*/
+ network_cp_fteid(&(ie->data.s5s8_pgw_c_fteid), data);
+ }
+ break;
+ }
+
+ case S11_IE_PAA: {
+ memcpy(&(ie->data.pdn_addr.pdn_type), data,
+ sizeof(ie->data.pdn_addr.pdn_type));
+ memcpy(&(ie->data.pdn_addr.ip_type.ipv4), data+1, sizeof(int));
+ break;
+ }
+
+ case S11_IE_APN_RESTRICTION:
+ break;
+
+ case S11_IE_BEARER_CTX:
+ parse_bearer_ctx(&(ie->data.bearer), data, ntohs(ie->header.ie_len));
+ break;
+
+ default:
+ log_msg(LOG_ERROR, "Unhandled S11 IE: %d\n", ie->header.ie_type);
+ }
+
+ msg += (ntohs(((struct s11_IE_header*)msg)->ie_len) + sizeof(struct s11_IE_header)) ; /*goto next IE*/
+ }
+ return SUCCESS;
+}
+
+void
+handle_s11_message(void *message)
+{
+ log_msg(LOG_INFO, "S11 recv msg handler.\n");
+
+ MsgBuffer* msgBuf_p = (MsgBuffer*)(message);
+
+ GtpV2MessageHeader msgHeader;
+
+ bool rc = GtpV2Stack_decodeMessageHeader(gtpStack_gp, &msgHeader, msgBuf_p);
+
+ switch(msgHeader.msgType){
+ case S11_GTP_CREATE_SESSION_RESP:
+ s11_CS_resp_handler(msgBuf_p, &msgHeader);
+ break;
+
+ case S11_GTP_MODIFY_BEARER_RESP:
+ s11_MB_resp_handler(msgBuf_p, &msgHeader);
+ break;
+
+ case S11_GTP_DELETE_SESSION_RESP:
+ s11_DS_resp_handler(msgBuf_p, &msgHeader);
+ break;
+
+ case S11_GTP_RELEASE_BEARER_RESP:
+ s11_RB_resp_handler(msgBuf_p, &msgHeader);
+ break;
+
+ case S11_GTP_DDN:
+ s11_DDN_handler(msgBuf_p, &msgHeader);
+ break;
+
+ }
+ return;
+}
diff --git a/src/s11/json_config.c b/src/s11/json_config.c
new file mode 100644
index 0000000..5c6c1af
--- /dev/null
+++ b/src/s11/json_config.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "json_data.h"
+#include "s11_config.h"
+#include "err_codes.h"
+
+s11_config g_s11_cfg;
+
+void
+init_parser(char *path)
+{
+ load_json(path);
+}
+
+int
+parse_s11_conf()
+{
+ /*s1ap information*/
+ g_s11_cfg.local_egtp_ip = get_ip_scalar("s11.egtp_local_addr");
+ if(-1 == g_s11_cfg.local_egtp_ip) return -1;
+ g_s11_cfg.egtp_def_port = get_int_scalar("s11.egtp_default_port");
+ if(-1 == g_s11_cfg.egtp_def_port) return -1;
+
+ g_s11_cfg.sgw_ip = get_ip_scalar("s11.sgw_addr");
+ if(-1 == g_s11_cfg.sgw_ip) return -1;
+ g_s11_cfg.pgw_ip = get_ip_scalar("s11.pgw_addr");
+ if(-1 == g_s11_cfg.pgw_ip) return -1;
+
+ return SUCCESS;
+}
diff --git a/src/s11/main.c b/src/s11/main.c
new file mode 100644
index 0000000..489a433
--- /dev/null
+++ b/src/s11/main.c
@@ -0,0 +1,274 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+
+#include "thread_pool.h"
+#include "err_codes.h"
+#include "options.h"
+#include "ipc_api.h"
+#include "message_queues.h"
+#include "s11.h"
+#include "s11_config.h"
+#include <sys/types.h>
+#include "msgType.h"
+#include "../gtpV2Codec/gtpV2StackWrappers.h"
+/**Global and externs **/
+extern s11_config g_s11_cfg;
+
+/*S11 CP communication parameters*/
+int g_s11_fd;
+struct sockaddr_in g_s11_cp_addr;
+socklen_t g_s11_serv_size;
+struct sockaddr_in g_client_addr;
+socklen_t g_client_addr_size;
+int ipc_reader_tipc_s11;
+
+/*Connections to send response(CS/MB) to mme-app*/
+int g_resp_fd;
+
+pthread_t tipcReaderS11_t;
+
+pthread_mutex_t s11_net_lock = PTHREAD_MUTEX_INITIALIZER;
+
+struct thread_pool *g_tpool;
+struct thread_pool *g_tpool_tipc_reader_s11;
+/**End: global and externs**/
+
+extern char processName[255];
+extern int pid;
+
+
+void
+handle_mmeapp_message_s11(void * data)
+{
+ char *msg = ((char *) data) + (sizeof(uint32_t)*2);
+
+ msg_type_t* msg_type = (msg_type_t*)(msg);
+
+ switch(*msg_type)
+ {
+ case create_session_request:
+ create_session_handler(msg);
+ break;
+ case modify_bearer_request:
+ modify_bearer_handler(msg);
+ break;
+ case delete_session_request:
+ delete_session_handler(msg);
+ break;
+ case release_bearer_request:
+ release_bearer_handler(msg);
+ break;
+ case ddn_acknowledgement:
+ ddn_ack_handler(msg);
+ break;
+ default:
+ break;
+ }
+ free(data);
+}
+
+void * tipc_msg_handler_s11()
+{
+ int bytesRead = 0;
+ while (1)
+ {
+ unsigned char buffer[255] = {0};
+ if ((bytesRead = read_tipc_msg(ipc_reader_tipc_s11, buffer, 255)) > 0)
+ {
+ unsigned char *tmpBuf = (unsigned char *) malloc(sizeof(char) * bytesRead);
+ memcpy(tmpBuf, buffer, bytesRead);
+ log_msg(LOG_INFO, "S11 message received from mme-app");
+ insert_job(g_tpool_tipc_reader_s11, handle_mmeapp_message_s11, tmpBuf);
+ }
+ }
+}
+struct GtpV2Stack* gtpStack_gp = NULL;
+extern struct MsgBuffer* csReqMsgBuf_p;
+extern struct MsgBuffer* mbReqMsgBuf_p;
+extern struct MsgBuffer* dsReqMsgBuf_p;
+extern struct MsgBuffer* rbReqMsgBuf_p;
+extern struct MsgBuffer* ddnAckMsgBuf_p;
+
+int
+init_s11_workers()
+{
+ if ((ipc_reader_tipc_s11 = create_tipc_socket()) <= 0)
+ {
+ log_msg(LOG_ERROR, "Failed to create IPC Reader tipc socket \n");
+ return -E_FAIL;
+ }
+ if ( bind_tipc_socket(ipc_reader_tipc_s11, s11AppInstanceNum_c) != 1)
+ {
+ log_msg(LOG_ERROR, "Failed to bind IPC Reader tipc socket \n");
+ return -E_FAIL;
+ }
+
+ /* Initialize thread pool for mme-app messages */
+ g_tpool_tipc_reader_s11 = thread_pool_new(3);
+
+ if (g_tpool_tipc_reader_s11 == NULL) {
+ log_msg(LOG_ERROR, "Error in creating thread pool. \n");
+ return -E_FAIL_INIT;
+ }
+
+ log_msg(LOG_INFO, "S11 Listener thead pool initalized.\n");
+
+ // thread to read incoming ipc messages from tipc socket
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ pthread_create(&tipcReaderS11_t, &attr, &tipc_msg_handler_s11, NULL);
+ pthread_attr_destroy(&attr);
+
+ return 0;
+}
+
+/*Initialize sctp socket connection for eNB*/
+int
+init_gtpv2()
+{
+ /*Create UDP socket*/
+ g_s11_fd = socket(PF_INET, SOCK_DGRAM, 0);
+
+ g_client_addr.sin_family = AF_INET;
+ //g_client_addr.sin_addr.s_addr = htonl(g_s11_cfg.local_egtp_ip);
+ g_client_addr.sin_addr.s_addr = htonl(g_s11_cfg.local_egtp_ip);
+ fprintf(stderr, "....................local egtp %d\n", g_s11_cfg.local_egtp_ip);
+ //g_client_addr.sin_port = htons(0); /* TODO: Read value from config */
+ g_client_addr.sin_port = htons(g_s11_cfg.egtp_def_port);
+
+ bind(g_s11_fd, (struct sockaddr *)&g_client_addr, sizeof(g_client_addr));
+ g_client_addr_size = sizeof(g_client_addr);
+
+ /*Configure settings in address struct*/
+ g_s11_cp_addr.sin_family = AF_INET;
+ //g_s11_cp_addr.sin_port = htons(g_s11_cfg.egtp_def_port);
+ fprintf(stderr, ".................... egtp def port %d\n", g_s11_cfg.egtp_def_port);
+ g_s11_cp_addr.sin_port = htons(g_s11_cfg.egtp_def_port);
+ //g_s11_cp_addr.sin_addr.s_addr = htonl(g_s11_cfg.sgw_ip);
+ fprintf(stderr, "....................sgw ip %d\n", g_s11_cfg.sgw_ip);
+ g_s11_cp_addr.sin_addr.s_addr = htonl(g_s11_cfg.sgw_ip);
+ memset(g_s11_cp_addr.sin_zero, '\0', sizeof(g_s11_cp_addr.sin_zero));
+
+ g_s11_serv_size = sizeof(g_s11_cp_addr);
+
+ return SUCCESS;
+}
+
+/**
+ Opening pipe connection from S11 app to MME(Single queue pipe)
+*/
+int
+init_s11_ipc()
+{
+ log_msg(LOG_INFO, "Connecting to mme-app S11 CS response queue\n");
+ if ((g_resp_fd = create_tipc_socket()) <= 0)
+ return -E_FAIL;
+
+ log_msg(LOG_INFO, "S11 - mme-app IPC: Connected.\n");
+
+ return 0;
+}
+
+/**
+ Read incoming S11 messages and pass to threadpool
+ for processing.
+*/
+void
+s11_reader()
+{
+ unsigned char buffer[S11_GTPV2C_BUF_LEN];
+ int len;
+
+ while(1) {
+ //len = recvfrom(g_s11_fd, buffer, S11_GTPV2C_BUF_LEN, 0,
+ // &g_client_addr, &g_client_addr_size);
+ len = recvfrom(g_s11_fd, buffer, S11_GTPV2C_BUF_LEN, 0,
+ (struct sockaddr*)&g_s11_cp_addr, &g_s11_serv_size);
+
+ if(len > 0) {
+ MsgBuffer* tmp_buf_p = createMsgBuffer(len);
+ MsgBuffer_writeBytes(tmp_buf_p, buffer, len, true);
+ MsgBuffer_rewind(tmp_buf_p);
+ log_msg(LOG_INFO, "S11 Received msg len : %d \n",len);
+ insert_job(g_tpool, handle_s11_message, tmp_buf_p);
+ }
+
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ memcpy (processName, argv[0], strlen(argv[0]));
+ pid = getpid();
+
+ init_parser("conf/s11.json");
+ parse_s11_conf();
+
+ // init stack
+ gtpStack_gp = createGtpV2Stack();
+ if (gtpStack_gp == NULL)
+ {
+ log_msg(LOG_ERROR, "Error in initializing ipc.\n");
+ return -1;
+ }
+
+ csReqMsgBuf_p = createMsgBuffer(4096);
+ mbReqMsgBuf_p = createMsgBuffer(4096);
+ dsReqMsgBuf_p = createMsgBuffer(4096);
+ rbReqMsgBuf_p = createMsgBuffer(4096);
+ ddnAckMsgBuf_p = createMsgBuffer(4096);
+
+ if (csReqMsgBuf_p == NULL || mbReqMsgBuf_p == NULL || dsReqMsgBuf_p == NULL || rbReqMsgBuf_p == NULL || ddnAckMsgBuf_p == NULL)
+ {
+ log_msg(LOG_ERROR, "Error in initializing msg buffers required by gtp codec.\n");
+ return -1;
+ }
+
+ /*Init writer sockets*/
+ if (init_s11_ipc() != 0) {
+ log_msg(LOG_ERROR, "Error in initializing ipc.\n");
+ return -1;
+ }
+
+ init_s11_workers();
+
+ /* Initialize thread pool for S11 messages from CP*/
+ g_tpool = thread_pool_new(S11_THREADPOOL_SIZE);
+
+ if (g_tpool == NULL) {
+ log_msg(LOG_ERROR, "Error in creating thread pool. \n");
+ return -1;
+ }
+ log_msg(LOG_INFO, "S11 listener threadpool initialized.\n");
+
+ if (init_gtpv2() != 0)
+ return -1;
+
+ s11_reader();
+
+ return 0;
+}
diff --git a/src/s11/options.c b/src/s11/options.c
new file mode 100644
index 0000000..aa537e3
--- /dev/null
+++ b/src/s11/options.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <getopt.h>
+
+#include "options.h"
+#include "log.h"
+
+void parse_args(int argc, char **argv)
+{
+ int args_set = 0;
+ int c = 0;
+
+ const struct option long_options[] = {
+ {"config_file", required_argument, NULL, 'f'},
+ {0, 0, 0, 0}
+ };
+
+ do {
+ int option_index = 0;
+
+ c = getopt_long(argc, argv, "f:", long_options,
+ &option_index);
+
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'f':
+ break;
+ default:
+ log_msg(LOG_ERROR, "Unknown argument - %s.", argv[optind]);
+ exit(0);
+ }
+ } while (c != -1);
+
+ if ((args_set & REQ_ARGS) != REQ_ARGS) {
+ log_msg(LOG_ERROR, "Usage: %s\n", argv[0]);
+ for (c = 0; long_options[c].name; ++c) {
+ log_msg(LOG_ERROR, "\t[ -%s | -%c ] %s\n",
+ long_options[c].name,
+ long_options[c].val,
+ long_options[c].name);
+ }
+ exit(0);
+ }
+}
+