MME2 changes - Propped commits from openmme/paging branch. Added scripts
for code gen

Change-Id: Ie55032217232214ac8544ca76ea34335205329e4
diff --git a/include/common/3gpp_24008.h b/include/common/3gpp_24008.h
new file mode 100644
index 0000000..37c55bc
--- /dev/null
+++ b/include/common/3gpp_24008.h
@@ -0,0 +1,11 @@
+#ifndef __3gpp_24008_h__
+#define __3gpp_24008_h__
+
+/* UE Types */
+
+#define ID_IMSI  1
+#define ID_IMEI  2
+#define ID_IMEISV  3
+#define ID_TMSI  4
+
+#endif
diff --git a/include/common/common_proc_info.h b/include/common/common_proc_info.h
new file mode 100644
index 0000000..d390878
--- /dev/null
+++ b/include/common/common_proc_info.h
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+
+#ifndef __S11_COMMON_PROC_INFO_H_
+#define __S11_COMMON_PROC_INFO_H_
+
+#include "err_codes.h"
+#include "s1ap_structs.h"
+#include "s1ap_ie.h"
+#include "s11_structs.h"
+
+struct s1ap_common_req_Q_msg {
+    int             IE_type; 
+	int ue_idx;
+	int enb_fd;
+	int enb_s1ap_ue_id;
+	int mme_s1ap_ue_id;
+    enum s1ap_cn_domain cn_domain;
+    unsigned char imsi[BINARY_IMSI_LEN];
+	struct TAI      tai;//TODO: will be list of 16 TAI's for UE.
+	s1apCause_t cause;
+
+	unsigned long ueag_max_ul_bitrate;
+	unsigned long ueag_max_dl_bitrate;
+	struct fteid gtp_teid;
+	unsigned char sec_key[32];
+	unsigned char bearer_id;
+};
+
+struct s11_req_Q_msg {
+    int         IE_type; 
+	struct fteid s11_sgw_c_fteid;
+};
+
+struct s11_resp_Q_msg {
+    int         IE_type; 
+	int 		ue_idx;
+};
+
+enum s1ap_common_req_type
+{
+    S1AP_CTX_REL_REQ,
+    S1AP_CTX_REL_CMD,
+    S1AP_INIT_CTXT_SETUP_REQ,
+    S1AP_PAGING_REQ,
+    S1AP_REQ_UNKNOWN
+};
+
+enum s11_common_req_type
+{
+    S11_RABR_REQ,
+    S11_REQ_UNKNOWN
+};
+
+enum s11_common_resp_type
+{
+    S11_RABR_RESP,
+    S11_RESP_UNKNOWN
+};
+
+#define S1AP_COMMON_REQ_BUF_SIZE sizeof(struct s1ap_common_req_Q_msg)
+
+#define S11_COMM_REQ_STAGE_BUF_SIZE sizeof(struct s11_req_Q_msg)
+#define S11_COMM_RES_STAGE_BUF_SIZE sizeof(struct s11_resp_Q_msg)
+
+#endif /*__S11_COMMON_PROC_INFO_H_*/
+
diff --git a/include/common/err_codes.h b/include/common/err_codes.h
new file mode 100644
index 0000000..9ef2fd8
--- /dev/null
+++ b/include/common/err_codes.h
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+#ifndef ERROR_CODES_H_
+#define ERROR_CODES_H_
+
+/***
+Common error codes across MME
+*/
+
+enum ERROR_CODES{
+	SUCCESS = 0,
+	/*Generic error codes 0-100*/
+	E_FAIL,
+	E_FAIL_INIT, /*Failed in initialization*/
+	E_ALLOC_FAILED,
+	E_PARSING_FAILED,
+
+	/*S1AP error codes 200-300 */
+	S1AP_AUTH_FAILED = 201,
+	S1AP_SECMODE_FAILED,
+	S1AP_IDENTITY_FAILED,
+
+	/*S6a error codes 300-500*/
+	S6A_AIA_FAILED = 301,
+	S6A_FD_ERROR,
+	S6A_FD_CORE_INIT_FAILED,
+	S6A_FD_CORE_PARSECONF_FAILED,
+	S6A_FD_CORE_START_FAILED,
+	S6A_FD_GET_DICTVAL_FAILED,
+	S6A_FD_DICTSRCH_FAILED,
+};
+
+#endif /* ERROR_CODES_H__*/
diff --git a/include/common/f8.h b/include/common/f8.h
new file mode 100644
index 0000000..df3ef81
--- /dev/null
+++ b/include/common/f8.h
@@ -0,0 +1,37 @@
+/*-----------------------------------------------
+ * * f8.h
+ * *---------------------------------------------
+ */
+
+/* The code has been referred from
+ * 1. https://www.gsma.com/aboutus/wp-content/uploads/2014/12/uea2uia2d1v21.pdf
+ * 2. https://www.gsma.com/aboutus/wp-content/uploads/2014/12/snow3gspec.pdf
+ */
+
+
+#ifndef F8_H_
+#define F8_H_
+#include "snow_3g.h"
+
+
+/* f8.
+ * Input key: 128 bit Confidentiality Key.
+ * Input count:32-bit Count, Frame dependent input.
+ * Input bearer: 5-bit Bearer identity (in the LSB side).
+ * Input dir:1 bit, direction of transmission.
+ * Input data: length number of bits, input bit stream.
+ * Input length: 32 bit Length, i.e., the number of bits to be encrypted or
+ * decrypted.
+ * Output data: Output bit stream. Assumes data is suitably memory
+ * allocated.
+ * Encrypts/decrypts blocks of data between 1 and 2^32 bits in length as
+ * defined in Section 3 of
+ * https://www.gsma.com/aboutus/wp-content/uploads/2014/12/snow3gspec.pdf
+ * specs document
+*/
+
+
+void f8( u8 *key, u32 count, u32 bearer, u32 dir, u8 *data, u32 length );
+
+
+#endif
diff --git a/include/common/f9.h b/include/common/f9.h
new file mode 100644
index 0000000..e7e9ff1
--- /dev/null
+++ b/include/common/f9.h
@@ -0,0 +1,33 @@
+/*--------------------------------------------------------
+ * f9.h
+ *--------------------------------------------------------
+*/
+
+
+/* The code has been referred from
+ * 1.https://www.gsma.com/aboutus/wp-content/uploads/2014/12/uea2uia2d1v21.pdf
+ * 2.https://www.gsma.com/aboutus/wp-content/uploads/2014/12/snow3gspec.pdf
+*/
+
+#ifndef F9_H_
+#define F9_H_
+#include "snow_3g.h"
+
+/* f9.
+ * Input key: 128 bit Integrity Key.
+ * Input count:32-bit Count, Frame dependent input.
+ * Input fresh: 32-bit Random number.
+ * Input dir:1 bit, direction of transmission (in the LSB).
+ * Input data: length number of bits, input bit stream.
+ * Input length: 64 bit Length, i.e., the number of bits to be MAC'd.
+ * Output : 32 bit block used as MAC
+ * Generates 32-bit MAC using UIA2 algorithm as defined in Section 4
+ * of https://www.gsma.com/aboutus/wp-content/uploads/2014/12/snow3gspec.pdf
+ * specs document.
+ */
+
+
+u8* f9( u8* key, u32 count, u32 fresh, u32 dir, u8 *data, u64 length);
+
+#endif
+
diff --git a/include/common/hss_message.h b/include/common/hss_message.h
new file mode 100644
index 0000000..2835fcb
--- /dev/null
+++ b/include/common/hss_message.h
@@ -0,0 +1,102 @@
+/*
+ * 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.
+ */
+
+#ifndef __HSS_MSG_H_
+#define __HSS_MSG_H_
+
+#include "sec.h"
+
+/*Information needed for AIR*/
+enum e_BUF_HDR {
+	HSS_AIR_MSG,
+	HSS_AIA_MSG,
+	HSS_ULR_MSG,
+	HSS_ULA_MSG,
+	//NI Detach
+	HSS_CLR_MSG,
+	HSS_CLA_MSG,
+	//NI Detach
+	HSS_PURGE_MSG,
+	HSS_PURGE_RESP_MSG,
+};
+
+
+#define IMSI_STR_LEN 16
+/*AIR  - request. Struct is same for ULR*/
+struct hss_air_msg {
+	char imsi[IMSI_STR_LEN];
+	unsigned char  plmn_id[3];
+};
+
+/*AIA  - response*/
+struct hss_aia_msg {
+	struct RAND rand;
+	struct XRES xres;
+	struct AUTN autn;
+	struct KASME kasme;
+};
+
+#define HSS_MSISDN_LEN 10
+#define SPARE_LEN 52
+
+/*ULA  - response*/
+struct hss_ula_msg {
+	int subscription_state;
+	unsigned char msisdn[HSS_MSISDN_LEN];
+	unsigned char a_msisdn[HSS_MSISDN_LEN];
+	unsigned char spare[SPARE_LEN];
+};
+
+struct hss_clr_msg {
+	char origin_host;
+	char origin_realm;
+	char user_name;
+	unsigned char cancellation_type;
+};
+
+
+struct hss_pur_msg {
+	int ue_idx;
+	char imsi[IMSI_STR_LEN];
+};
+
+struct hss_req_msg {
+	enum e_BUF_HDR hdr;
+	int ue_idx;
+	union req_data {
+		struct hss_air_msg air;
+	}data;
+};
+
+struct hss_resp_msg {
+	enum e_BUF_HDR hdr;
+	int ue_idx;
+	int result;
+	union resp_data {
+		struct hss_aia_msg aia;
+		struct hss_ula_msg ula;
+		struct hss_clr_msg clr;
+	}data;
+};
+
+#define HSS_RCV_BUF_SIZE 128
+#define HSS_REQ_MSG_SIZE sizeof(struct hss_req_msg)
+#define HSS_RESP_MSG_SIZE sizeof(struct hss_resp_msg)
+
+#endif /*__STAGE6_S6A_MSG_H_*/
+
diff --git a/include/common/ipc_api.h b/include/common/ipc_api.h
new file mode 100644
index 0000000..92ae5ce
--- /dev/null
+++ b/include/common/ipc_api.h
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+
+#ifndef IPC_API_H_
+#define IPC_API_H_
+
+#include <tipcTypes.h>
+
+#define		IPC_MAX_BUFFER_SIZE		1024
+
+#define IPC_MODE 0664
+
+enum ipc_access_mode {
+	IPC_READ = 01,
+	IPC_WRITE = 02,
+};
+
+typedef int ipc_handle;
+
+int
+create_ipc_channel(char *name);
+
+int
+open_ipc_channel(char *name, enum ipc_access_mode access_mode);
+
+int
+create_open_ipc_channel(char *name,
+		enum ipc_access_mode access_mode);
+
+int
+read_ipc_channel(ipc_handle fd, char *buffer, size_t size);
+
+int
+write_ipc_channel(ipc_handle fd, char *buffer, size_t size);
+
+int
+close_ipc_channel(ipc_handle fd);
+
+int
+create_tipc_socket();
+
+int
+bind_tipc_socket(int sockFd, uint32_t instanceNum);
+
+int
+send_tipc_message(int sd, uint32_t destAddr, void * buf, int len);
+
+int
+read_tipc_msg(int sockFd, void * buf, int len);
+
+void
+close_tipc_socket(int sockFd);
+
+
+#endif /* IPC_API_H_ */
diff --git a/include/common/json_data.h b/include/common/json_data.h
new file mode 100644
index 0000000..0d4357b
--- /dev/null
+++ b/include/common/json_data.h
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+#ifndef __JSON_DATA_H_
+#define __JSON_DATA_H_
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+char *
+get_string_scalar(char *path);
+
+int
+get_ip_scalar(char *path);
+
+int
+get_int_scalar(char *path);
+
+int
+load_json(char *filename);
+
+#endif /**/
diff --git a/include/common/log.h b/include/common/log.h
new file mode 100644
index 0000000..d2d3953
--- /dev/null
+++ b/include/common/log.h
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+#ifndef __LOG_1_H_
+#define __LOG_1_H_
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+enum log_levels{
+	LOG_INFO,
+	LOG_DEBUG,
+	LOG_WARNING,
+	LOG_ERROR,
+};
+
+void log_message(int l, const char *file, int line, const char *fmt, ...);
+//#define log_msg(LOG_LEVEL, ARGS) set_log(#LOG_LEVEL, __FILE__, __LINE__, __VA_ARGS__)
+#define log_msg(LOG_LEVEL, ...) log_message( LOG_LEVEL, __FILE__, __LINE__,  __VA_ARGS__)
+//#define log_msg(LOG_LEVEL, ...) ;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LOG_1_H_ */
diff --git a/include/common/message_queues.h b/include/common/message_queues.h
new file mode 100644
index 0000000..faf719a
--- /dev/null
+++ b/include/common/message_queues.h
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+#ifndef __MESSAGE_QUEUES_H_
+#define __MESSAGE_QUEUES_H_
+
+#define S1AP_Q_DIR "/tmp/s1ap"
+#define MME_APP_Q_DIR "/tmp/mme-app"
+#define S6A_Q_DIR "/tmp/s6a"
+#define S11_Q_DIR "/tmp/s11"
+
+#define MME_TOTAL_HANDLERS 7
+
+/**
+Message queues used across MME, S1ap, S11, S6a
+**/
+
+
+/********** S1AP READ/WRITE QUEUE *************/
+#define S1AP_READ_QUEUE "/tmp/s1ap/s1ap_read_Q"
+#define S1AP_WRITE_QUEUE "/tmp/s1ap/s1ap_write_Q"
+
+/********** GTP READ/WRITE QUEUE *************/
+#define GTP_READ_QUEUE "/tmp/s11/gtp_read_Q"
+#define GTP_WRITE_QUEUE "/tmp/s11/gtp_write_Q"
+
+/********** S6 READ/WRITE QUEUE *************/
+#define S6_READ_QUEUE "/tmp/s6a/s6_read_Q"
+#define S6_WRITE_QUEUE "/tmp/s6a/s6_write_Q"
+
+#define S6A_REQ_STAGE1_QUEUE "/tmp/s6a/req_Q"
+#define S1AP_AUTHREQ_STAGE2_QUEUE "/tmp/s1ap/authq_stage2_Q"
+#define S1AP_SECREQ_STAGE3_QUEUE "/tmp/s1ap/secreq_stage3_Q"
+#define S1AP_ESMREQ_STAGE4_QUEUE "/tmp/s1ap/esmreq_stage4_Q"
+#define S11_CSREQ_STAGE5_QUEUE "/tmp/s11/CSreq_stage5_Q"
+#define S1AP_ICSREQ_STAGE6_QUEUE "/tmp/s1ap/icsreq_stage6_Q"
+#define S11_MBREQ_STAGE7_QUEUE "/tmp/s11/MBreq_stage7_Q"
+#define S11_DTCHREQ_STAGE1_QUEUE   "/tmp/mme-app/s11_dtchreq_stage1_Q"
+#define S6A_DTCHREQ_STAGE1_QUEUE  "/tmp/mme-app/s6a_dtchreq_stage1_Q"
+#define S1AP_DTCHACCEPT_STAGE2_QUEUE "/tmp/mme-app/s1ap_dtchaccept_stage2_Q"
+#define S6A_PURGE_STAGE2_QUEUE "/tmp/s6a/PURGE_Q"
+
+#endif /*__MESSAGE_QUEUES_H*/
diff --git a/include/common/msgType.h b/include/common/msgType.h
new file mode 100644
index 0000000..f4a13b5
--- /dev/null
+++ b/include/common/msgType.h
@@ -0,0 +1,519 @@
+/*
+ * 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.
+ */
+
+#ifndef INCLUDE_COMMON_MSGTYPE_H_
+#define INCLUDE_COMMON_MSGTYPE_H_
+
+#include "err_codes.h"
+#include "s11_structs.h"
+#include "s1ap_structs.h"
+#include "s1ap_ie.h"
+
+
+#define NAS_RAND_SIZE 16
+#define NAS_AUTN_SIZE 16
+
+typedef enum msg_data_t
+{
+    ue_data = 0,
+    session_data
+}msg_data_t;
+
+typedef enum msg_type_t {
+    attach_request = 0,
+    auth_info_request,
+    auth_info_answer,
+    update_loc_request,
+    update_loc_answer,
+    auth_request,
+    auth_response,
+    id_request,
+    id_response,
+    sec_mode_command,
+    sec_mode_complete,
+    esm_info_request,
+    esm_info_response,
+    create_session_request,
+    create_session_response,
+    init_ctxt_request,
+    init_ctxt_response,
+    modify_bearer_request,
+    modify_bearer_response,
+    attach_complete,
+    detach_request,
+    detach_accept,
+    purge_request,
+    purge_answser,
+    delete_session_request,
+    delete_session_response,
+    s1_release_request,
+    s1_release_command,
+    s1_release_complete,
+    release_bearer_request,
+    release_bearer_response,
+    ni_detach_request,
+    detach_accept_from_ue,
+    cancel_location_request,
+    cancel_location_answer,
+    downlink_data_notification,
+    ddn_acknowledgement,
+    paging_request,
+    service_request,
+    ics_req_paging,
+    tau_request,
+    tau_response,
+    max_msg_type
+} msg_type_t;
+
+
+/*************************
+ * Incoming S1AP Messages
+ *************************/
+struct ue_attach_info {
+    int s1ap_enb_ue_id;
+    int criticality;
+    unsigned char IMSI[BINARY_IMSI_LEN];
+    struct TAI tai;
+    struct CGI utran_cgi;
+    struct MS_net_capab ms_net_capab;
+    struct UE_net_capab ue_net_capab;
+    enum ie_RRC_est_cause rrc_cause;
+    int enb_fd;
+    char esm_info_tx_required;
+    unsigned char pti;
+    unsigned int  flags; /* imsi - 0x00000001, GUTI - 0x00000002 */
+    guti mi_guti;
+    unsigned char seq_no;
+    unsigned char dns_present;
+    unsigned short int pco_options[10];
+	
+};
+
+struct authresp_Q_msg {
+    int status;
+    struct XRES res;
+	struct AUTS auts;
+};
+
+struct secmode_resp_Q_msg {
+    int ue_idx;
+    int status;
+};
+
+struct esm_resp_Q_msg {
+    int status;
+    struct apn_name apn;
+};
+
+struct initctx_resp_Q_msg{
+    unsigned short 	eRAB_id;
+    unsigned int 	transp_layer_addr;
+    unsigned int 	gtp_teid;
+};
+
+struct attach_complete_Q_msg {
+    unsigned short	status;
+};
+
+struct service_req_Q_msg {
+        int enb_fd;
+        unsigned int ksi;
+        unsigned int seq_no;
+        unsigned short mac;
+        struct TAI tai;
+        struct CGI utran_cgi;
+        struct STMSI s_tmsi;
+};
+
+struct tauReq_Q_msg {
+    int seq_num;
+    int enb_fd;
+};
+
+struct identityResp_Q_msg {
+	int status;
+	unsigned char IMSI[BINARY_IMSI_LEN];
+};
+
+struct detach_req_Q_msg {
+	int ue_m_tmsi;
+};
+
+typedef union s1_incoming_msgs_t {
+    struct ue_attach_info ue_attach_info_m;
+    struct authresp_Q_msg authresp_Q_msg_m;
+    struct secmode_resp_Q_msg secmode_resp_Q_msg_m;
+    struct esm_resp_Q_msg esm_resp_Q_msg_m;
+    struct initctx_resp_Q_msg initctx_resp_Q_msg_m;
+    struct attach_complete_Q_msg attach_complete_Q_msg_m;
+    struct service_req_Q_msg service_req_Q_msg_m;
+    struct identityResp_Q_msg identityResp_Q_msg_m;
+    struct tauReq_Q_msg tauReq_Q_msg_m;
+    struct detach_req_Q_msg detachReq_Q_msg_m;
+}s1_incoming_msgs_t;
+
+typedef struct s1_incoming_msg_data_t {
+    uint32_t destInstAddr;
+    uint32_t srcInstAddr;
+    msg_type_t msg_type;
+    int ue_idx;
+    int s1ap_enb_ue_id;
+    s1_incoming_msgs_t msg_data;
+}s1_incoming_msg_data_t;
+
+#define S1_READ_MSG_BUF_SIZE sizeof(s1_incoming_msg_data_t)
+
+/*************************
+ * Outgoing S1AP Messages
+ *************************/
+struct authreq_info {
+		msg_type_t msg_type;
+    	int ue_idx;
+    	int enb_s1ap_ue_id;
+    	unsigned char rand[NAS_RAND_SIZE];
+    	unsigned char autn[NAS_AUTN_SIZE];
+     	//struct TAI tai;
+    	int enb_fd;
+};
+
+#define S1AP_AUTHREQ_STAGE2_BUF_SIZE sizeof(struct authreq_info)
+
+struct sec_mode_Q_msg {
+		msg_type_t msg_type;
+    	int ue_idx;
+    	int enb_s1ap_ue_id;
+    	struct UE_net_capab ue_network;
+		struct MS_net_capab  ms_net_capab;
+    	struct KASME key;
+    	uint8_t int_key[NAS_INT_KEY_SIZE];
+    	uint32_t dl_seq_no;
+    	int enb_fd;
+};
+
+#define S1AP_SECREQ_STAGE3_BUF_SIZE sizeof(struct sec_mode_Q_msg)
+
+
+struct esm_req_Q_msg {
+	msg_type_t msg_type;
+	int ue_idx;
+	int enb_s1ap_ue_id;
+	uint8_t pti;
+	uint8_t int_key[NAS_INT_KEY_SIZE];
+	unsigned short dl_seq_no;
+	int enb_fd;
+};
+
+#define S1AP_ESMREQ_STAGE4_BUF_SIZE sizeof(struct esm_req_Q_msg)
+
+struct init_ctx_req_Q_msg {
+	msg_type_t msg_type;
+	int ue_idx;
+	int enb_s1ap_ue_id;
+	unsigned long exg_max_ul_bitrate;
+	unsigned long exg_max_dl_bitrate;
+	struct fteid gtp_teid;
+	struct TAI tai;
+	struct apn_name apn;
+	struct PAA pdn_addr;
+	unsigned char sec_key[32];
+	unsigned char bearer_id;
+	uint8_t int_key[NAS_INT_KEY_SIZE];
+	uint16_t dl_seq_no;
+	int enb_fd;
+	unsigned char pti;
+	unsigned int m_tmsi;
+};
+
+#define S1AP_ICSREQ_STAGE6_BUF_SIZE sizeof(struct init_ctx_req_Q_msg)
+
+struct detach_accept_Q_msg {
+	msg_type_t msg_type;
+	int ue_idx;
+	int enb_s1ap_ue_id;
+	uint8_t int_key[NAS_INT_KEY_SIZE];
+	uint16_t dl_seq_no;
+	int enb_fd;
+};
+
+#define S1AP_DTCHACCEPT_STAGE2_BUF_SIZE sizeof(struct detach_accept_Q_msg)
+
+
+struct s1relcmd_info{
+	msg_type_t msg_type;
+	int ue_idx;
+	int enb_s1ap_ue_id;
+	int enb_fd;
+	s1apCause_t cause;
+};
+#define S1AP_RELCMD_STAGE2_BUF_SIZE sizeof(struct s1relcmd_info)
+
+
+struct ni_detach_request_Q_msg {
+    msg_type_t msg_type;
+    int ue_idx;
+    int enb_s1ap_ue_id;
+    uint8_t int_key[NAS_INT_KEY_SIZE];
+    uint16_t dl_seq_no;
+    int enb_fd;
+    unsigned char detach_type;
+};
+#define S1AP_NI_DTCHREQUEST_BUF_SIZE sizeof(struct ni_detach_request_Q_msg)
+
+struct paging_req_Q_msg {
+	msg_type_t msg_type;
+        int ue_idx;
+        int enb_s1ap_ue_id;
+        int enb_fd;
+	enum s1ap_cn_domain cn_domain;
+	unsigned char IMSI[BINARY_IMSI_LEN];
+	struct TAI tai;
+};
+#define PAGING_REQUEST_BUF_SIZE sizeof(struct paging_req_Q_msg)
+
+struct ics_req_paging_Q_msg {
+	msg_type_t msg_type;
+    int ue_idx;
+    int enb_s1ap_ue_id;
+    int enb_fd;
+	unsigned long ueag_max_ul_bitrate;
+	unsigned long ueag_max_dl_bitrate;
+	unsigned char bearer_id;
+	struct fteid gtp_teid;
+	unsigned char sec_key[32];
+};
+#define ICS_REQ_PAGING_BUF_SIZE sizeof(struct ics_req_paging_Q_msg)
+
+struct attachReqRej_info
+{
+  msg_type_t msg_type;
+  int ue_idx; /*mme s1ap UE id*/
+  int s1ap_enb_ue_id;
+  int enb_fd;
+  unsigned char cause;
+};
+#define S1AP_REQ_REJECT_BUF_SIZE sizeof(struct attachReqRej_info)
+
+struct attachIdReq_info
+{
+	msg_type_t msg_type;
+	int ue_idx; /*mme s1ap UE id*/
+	int s1ap_enb_ue_id;
+ 	int enb_fd;
+    unsigned char ue_type;
+};
+#define S1AP_ID_REQ_BUF_SIZE sizeof(struct attachIdReq_info)
+
+struct tauResp_Q_msg {
+	msg_type_t msg_type;
+	int ue_idx;
+	int enb_fd;
+	int s1ap_enb_ue_id;
+	int status;
+	int dl_seq_no;
+	uint8_t int_key[NAS_INT_KEY_SIZE];
+	struct TAI tai;
+	unsigned int m_tmsi;
+};
+#define S1AP_TAURESP_BUF_SIZE sizeof(struct tauResp_Q_msg)
+
+/*************************
+ * Outgoing GTP Messages
+ *************************/
+struct CS_Q_msg {
+	msg_type_t msg_type;
+	int ue_idx;
+	unsigned char IMSI[BINARY_IMSI_LEN];
+	struct apn_name apn;
+	struct TAI tai;
+	struct CGI utran_cgi;
+	unsigned char MSISDN[MSISDN_STR_LEN];
+	unsigned int max_requested_bw_dl;
+	unsigned int max_requested_bw_ul;
+	unsigned short int pco_options[10];
+};
+#define S11_CSREQ_STAGE5_BUF_SIZE sizeof(struct CS_Q_msg)
+
+#define S11_MB_INDICATION_FLAG_SIZE 3
+struct MB_Q_msg {
+	msg_type_t msg_type;
+	int ue_idx;
+	unsigned short indication[S11_MB_INDICATION_FLAG_SIZE];/*Provision*/
+	unsigned char bearer_id;
+	struct fteid s11_sgw_c_fteid;
+	struct fteid s1u_enb_fteid;
+};
+#define S11_MBREQ_STAGE7_BUF_SIZE sizeof(struct MB_Q_msg)
+
+#define S11_DS_INDICATION_FLAG_SIZE 3
+struct DS_Q_msg {
+	msg_type_t msg_type;
+	unsigned char indication[S11_DS_INDICATION_FLAG_SIZE];/*Provision*/
+	unsigned char bearer_id;
+	struct fteid s11_sgw_c_fteid;
+};
+#define S11_DTCHREQ_STAGE1_BUF_SIZE sizeof(struct DS_Q_msg)
+
+
+#define S11_RB_INDICATION_FLAG_SIZE 3
+struct RB_Q_msg{
+	msg_type_t msg_type;
+	int ue_idx;
+	unsigned short indication[S11_RB_INDICATION_FLAG_SIZE];
+	unsigned char bearer_id;
+	struct fteid s11_sgw_c_fteid;
+	struct fteid s1u_enb_fteid;
+};
+#define S11_RBREQ_STAGE1_BUF_SIZE sizeof(struct RB_Q_msg)
+
+struct DDN_ACK_Q_msg{
+        msg_type_t msg_type;
+        int ue_idx;
+        uint32_t seq_no;
+        uint8_t cause;
+};
+#define S11_DDN_ACK_BUF_SIZE sizeof(struct DDN_ACK_Q_msg)
+/*************************
+ * Incoming GTP Messages
+ *************************/
+struct csr_Q_msg {
+    int status;
+    struct fteid s11_sgw_fteid;
+    struct fteid s5s8_pgwc_fteid;
+    struct fteid s1u_sgw_fteid;
+    struct fteid s5s8_pgwu_fteid;
+    struct PAA pdn_addr;
+};
+
+struct MB_resp_Q_msg {
+    struct fteid s1u_sgw_fteid;
+};
+
+
+struct RB_resp_Q_msg {
+    struct fteid s1u_sgw_fteid;
+};
+
+struct ddn_Q_msg {
+    struct ARP arp;
+    uint8_t cause;
+    uint8_t eps_bearer_id;
+    uint32_t seq_no;
+};
+
+typedef union gtp_incoming_msgs_t {
+    struct csr_Q_msg csr_Q_msg_m;
+    struct MB_resp_Q_msg MB_resp_Q_msg_m;
+    struct RB_resp_Q_msg RB_resp_Q_msg_m;
+    struct ddn_Q_msg ddn_Q_msg_m;    
+}gtp_incoming_msgs_t;
+
+typedef struct gtp_incoming_msg_data_t {
+    uint32_t destInstAddr;
+    uint32_t srcInstAddr;
+    msg_type_t msg_type;
+    int ue_idx;
+    gtp_incoming_msgs_t msg_data;
+}gtp_incoming_msg_data_t;
+
+#define GTP_READ_MSG_BUF_SIZE sizeof(gtp_incoming_msg_data_t)
+
+/*************************
+ * Outgoing S6 Messages
+ *************************/
+struct s6a_Q_msg {
+	msg_type_t msg_type;
+	unsigned char imsi[16];
+	struct TAI tai;
+	struct AUTS auts;
+	unsigned int ue_idx;
+};
+#define S6A_REQ_Q_MSG_SIZE sizeof(struct s6a_Q_msg)
+
+struct s6a_purge_Q_msg {
+	int ue_idx;
+	unsigned char IMSI[BINARY_IMSI_LEN];
+};
+#define S6A_PURGEREQ_STAGE1_BUF_SIZE sizeof(struct s6a_purge_Q_msg)
+
+
+/*************************
+ * Incoming S6 Messages
+ *************************/
+typedef struct E_UTRAN_sec_vector {
+    struct RAND rand;
+    struct XRES xres;
+    struct AUTN autn;
+    struct KASME kasme;
+} E_UTRAN_sec_vector;
+
+struct aia_Q_msg {
+    int res;
+    E_UTRAN_sec_vector sec;
+};
+
+struct ula_Q_msg {
+    unsigned int access_restriction_data;
+    int subscription_status;
+    int net_access_mode;
+    unsigned int RAU_TAU_timer;
+    int res;
+    unsigned int max_requested_bw_dl;
+    unsigned int max_requested_bw_ul;
+    unsigned int apn_config_profile_ctx_id;
+    int all_APN_cfg_included_ind;
+    char MSISDN[MSISDN_STR_LEN];
+};
+
+struct purge_resp_Q_msg {
+    int status;
+};
+
+
+enum CancellationType {
+    MME_UPDATE_PROCEDURE = 0,
+    SGSN_UPDATE_PROCEDURE = 1,
+    SUBSCRIPTION_WITHDRAWAL = 2,
+    INVALID_TYPE
+};
+
+struct clr_Q_msg {
+    msg_type_t msg_type;
+    char origin_host[18];
+    char origin_realm[15];
+    uint8_t imsi[15];   
+    enum CancellationType c_type;
+};
+
+
+typedef union s6_incoming_msgs_t {
+    struct aia_Q_msg aia_Q_msg_m;
+    struct ula_Q_msg ula_Q_msg_m;
+    struct clr_Q_msg clr_Q_msg_m;	//NI Detach
+    struct purge_resp_Q_msg purge_resp_Q_msg_m;
+}s6_incoming_msgs_t;
+
+typedef struct s6_incoming_msg_data_t {
+	uint32_t destInstAddr;
+	uint32_t srcInstAddr;
+    	msg_type_t msg_type;
+    	int ue_idx;
+    	unsigned char IMSI[16];
+	s6_incoming_msgs_t msg_data;
+}s6_incoming_msg_data_t;
+
+#define S6_READ_MSG_BUF_SIZE sizeof(s6_incoming_msg_data_t)
+
+#endif /* INCLUDE_COMMON_MSGTYPE_H_ */
diff --git a/include/common/s11_structs.h b/include/common/s11_structs.h
new file mode 100644
index 0000000..c4ad8f9
--- /dev/null
+++ b/include/common/s11_structs.h
@@ -0,0 +1,130 @@
+/*
+ * 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.
+ */
+
+#ifndef __S11_STRUCTS_H_
+#define __S11_STRUCTS_H_
+
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+
+#pragma pack(1)
+typedef struct gtpv2c_header {
+	struct gtpc{
+		unsigned char spare :3;
+		unsigned char teidFlg :1;
+		unsigned char piggyback :1;
+		unsigned char version :3;
+		unsigned char message_type;
+		unsigned short len;
+	}gtp;
+	union teid {
+		struct has_teid_t {
+			unsigned int teid;
+			unsigned int seq :24;
+			unsigned int spare :8;
+		} has_teid;
+		struct no_teid_t {
+			unsigned int seq :24;
+			unsigned int spare :8;
+		} no_teid;
+	} teid;
+} gtpv2c_header;
+
+typedef struct fteid {
+        struct fteid_header {
+                unsigned char iface_type :6;
+                unsigned char v6 :1;
+                unsigned char v4 :1;
+                unsigned int teid_gre;
+        } header;
+        union ftied_ip {
+                struct in_addr ipv4;
+                struct in6_addr ipv6;
+                struct ipv4v6_t {
+                        struct in_addr ipv4;
+                        struct in6_addr ipv6;
+                } ipv4v6;
+        } ip;
+} fteid_t;
+
+struct PAA {
+	uint8_t pdn_type;
+        union ip_type {
+                struct in_addr ipv4;
+                struct ipv6_t {
+                        uint8_t prefix_length;
+                        struct in6_addr ipv6;
+                } ipv6;
+                struct paa_ipv4v6_t {
+                        uint8_t prefix_length;
+                        struct in6_addr ipv6;
+                        struct in_addr ipv4;
+                } paa_ipv4v6;
+        } ip_type;
+};
+
+struct gtp_cause {
+	unsigned char cause;
+	unsigned char data;
+};
+
+struct bearer_ctx {
+	unsigned char eps_bearer_id;
+	struct gtp_cause cause;
+	struct fteid s1u_sgw_teid;
+	struct fteid s5s8_pgw_u_teid;
+};
+
+struct ARP {
+        uint8_t prioLevel :4;
+        uint8_t preEmptionCapab :1;
+        uint8_t preEmptionVulnebility :1;
+        uint8_t spare :2;
+};
+
+
+struct s11_IE_header {
+	unsigned char ie_type;
+	unsigned short ie_len;
+	unsigned char cr_flag:4;
+	unsigned char instance:4;
+};
+
+union s11_IE_data {
+	struct gtp_cause cause;
+	struct fteid s11_sgw_fteid;
+	struct fteid s5s8_pgw_c_fteid;
+	struct PAA pdn_addr;
+	struct bearer_ctx bearer;
+};
+
+struct s11_IE {
+	struct s11_IE_header header;
+	union s11_IE_data data;
+};
+
+struct s11_proto_IE {
+	unsigned short message_type;
+	unsigned short no_of_ies;
+	struct s11_IE *s11_ies;
+};
+
+#pragma pack()
+
+#endif /* S11_STRUCTS_H */
diff --git a/include/common/s1ap_structs.h b/include/common/s1ap_structs.h
new file mode 100644
index 0000000..d61e13f
--- /dev/null
+++ b/include/common/s1ap_structs.h
@@ -0,0 +1,761 @@
+/*
+ * 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.
+ */
+
+#ifndef __S1AP_STRUCTS_H_
+#define __S1AP_STRUCTS_H_
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "sec.h"
+#include "ProcedureCode.h"
+#include "Criticality.h"
+#include "S1AP-PDU.h"
+#include "InitiatingMessage.h"
+
+#define NAS_RAND_SIZE 16
+#define NAS_AUTN_SIZE 16
+
+#define AUTH_REQ_NO_OF_IES 3
+#define SEC_MODE_NO_OF_IES 3
+#define ESM_REQ_NO_OF_IES 3
+#define ICS_REQ_NO_OF_IES 6
+#define DTCH_ACCEPT_NO_OF_IES 3
+#define UE_CTX_RELEASE_NO_OF_IES 3
+#define ATTACH_REJECT_NO_OF_IES 3
+
+#define ATTACH_ID_REQUEST_NO_OF_IES 3
+#define TAU_RSP_NO_OF_IES 3
+
+#define NI_UE_CTX_RELEASE_NO_OF_IES 3
+#define NI_DTCH_REQUEST_NO_OF_IES 3
+
+
+#define AUTH_REQ_NO_OF_NAS_IES 2
+#define SEC_MODE_NO_OF_NAS_IES 1
+#define ICS_REQ_NO_OF_NAS_IES 5
+#define TAU_RSP_NO_OF_NAS_IES 2
+
+#define SERVICE_REQ_SECURITY_HEADER 12
+#define SHORT_MAC_SIZE 2
+
+#define AUTHREQ_NAS_SECURITY_PARAM 0x01
+
+#define MSISDN_STR_LEN 10
+
+#define EMM_MAX_TAI_LIST 16
+
+#define SECURITY_KEY_SIZE 32
+
+#define MAC_SIZE 4
+#define AUTH_SYNC_FAILURE 21
+#define AUTH_RESPONSE 53
+/* ESM messages */
+ #define ESM_MSG_ACTV_DEF_BEAR__CTX_REQ 0xc1
+
+/*24.008 - 10.5.6.1
+APN name can be in range of min 3 octets to max 102 octets
+*/
+#define MAX_APN_LEN 102
+
+
+struct apn_name {
+	unsigned char len;
+	unsigned char val[MAX_APN_LEN];/*TODO: Make dynamic as range is big 3-102*/
+};
+
+/*TODO: Needed fro paging. Ignoring for now*/
+struct proto_conf {
+	int placeholder;
+};
+
+struct esm_sec_info {
+	struct proto_conf proto_config;
+};
+
+/*NAS MSG IE CODES */
+/* Message content : 
+   3gpp 24.301
+   Table 8.2.4.1: IEI Column.*/
+typedef enum
+{
+    NAS_IE_TYPE_EPS_MOBILE_ID_IMSI=0x1,
+    NAS_IE_TYPE_UE_NETWORK_CAPABILITY=0x2,
+    NAS_IE_TYPE_ESM_MSG=0x3,
+    NAS_IE_TYPE_TMSI_STATUS=0x09,
+    NAS_IE_TYPE_MS_NETWORK_FEATURE_SUPPORT=0x0C,
+    NAS_IE_TYPE_GUTI_TYPE=0x0E,
+    NAS_IE_TYPE_ADDITIONAL_UPDATE_TYPE=0xF,
+    NAS_IE_TYPE_MS_CLASSMARK_2=0x11,
+    NAS_IE_TYPE_LAI=0x13,
+    NAS_IE_TYPE_PTMSI_SIGNATURE=0x19,
+    NAS_IE_TYPE_MS_CLASSMARK_3=0x20,
+    NAS_IE_TYPE_APN=0x28,
+    NAS_IE_TYPE_AUTH_FAIL_PARAM=0x30,
+    NAS_IE_TYPE_MS_NETWORK_CAPABILITY=0x31,
+    NAS_IE_TYPE_DRX_PARAM=0x5C,
+    NAS_IE_TYPE_TAI=0x52,
+    NAS_IE_TYPE_VOICE_DOMAIN_PREF_UE_USAGE_SETTING=0x5D,
+    NAS_IE_TYPE_TX_FLAG=0xAA,
+    NAS_IE_TYPE_PCO=0xAB,
+    NAS_IE_TYPE_PTI=0xAC,
+}nas_ie_type;
+typedef struct MS_net_capab {
+    bool          pres;
+	unsigned char element_id;
+	unsigned char len;
+	unsigned char capab[6];
+}MS_net_capab;
+
+#if 0
+/* MS Network capability */
+typedef struct MS_net_capab {
+   unsigned char pres;
+   unsigned char len;
+   unsigned char gea1;
+   unsigned char smCapViaDdctdChan;
+   unsigned char smCapViaGprsChan;
+   unsigned char ucs2Supp;
+   unsigned char ssScrInd;
+   unsigned char soLsaCap;
+   unsigned char revLvlInd;
+   unsigned char pfcFeatMode;
+   unsigned char gea2;
+   unsigned char gea3;
+   unsigned char gea4;
+   unsigned char gea5;
+   unsigned char gea6;
+   unsigned char gea7;
+   unsigned char lcsVaCap;
+   unsigned char psInterRATho2UtranIuModeCap;
+   unsigned char psInterRATho2EutranS1ModeCap;
+   unsigned char csfbCap;
+   unsigned char isrSupp;
+   unsigned char srvcc2UtranCap;
+   unsigned char epcCap;
+}MS_net_capab;
+#endif
+
+struct UE_net_capab {
+	unsigned char len;
+	unsigned char capab[6];
+};
+#if 0
+/* UE Network capability */
+typedef struct UE_net_capab {
+   unsigned char pres;
+   unsigned char len;
+
+   unsigned char eea7;
+   unsigned char eea6;
+   unsigned char eea5;
+   unsigned char eea4;
+   unsigned char eea3;
+   unsigned char eea2_128;
+   unsigned char eea1_128;
+   unsigned char eea0;
+
+   unsigned char eia7;
+   unsigned char eia6;
+   unsigned char eia5;
+   unsigned char eia4;
+   unsigned char eia3;
+   unsigned char eia2_128;
+   unsigned char eia1_128;
+   unsigned char eia0;
+
+   unsigned char uea7;
+   unsigned char uea6;
+   unsigned char uea5;
+   unsigned char uea4;
+   unsigned char uea3;
+   unsigned char uea2;
+   unsigned char uea1;
+   unsigned char uea0;
+
+   unsigned char uia7;
+   unsigned char uia6;
+   unsigned char uia5;
+   unsigned char uia4;
+   unsigned char uia3;
+   unsigned char uia2;
+   unsigned char uia1;
+   unsigned char ucs2;
+
+   unsigned char vcc_1xsr;
+
+} UE_net_capab;
+#endif
+
+enum drx_params {
+	PAGINX_DRX32,
+	PAGINX_DRX64,
+	PAGINX_DRX128,
+	PAGINX_DRX256,
+	PAGINX_DRX512,
+};
+
+enum s1ap_cn_domain
+{
+    CN_DOMAIN_PS,
+    CN_DOMAIN_CS,
+    CN_DOMAIN_NONE
+};
+
+struct s1ap_header{
+	unsigned short procedure_code;
+	unsigned char criticality;
+};
+
+#pragma pack(1)
+
+/*36.413: 9.2.3.8 - MCC, MCN : Only 3 bytes are used*/
+struct PLMN {
+	unsigned char  idx[3];
+};
+
+struct TAI {
+	struct PLMN plmn_id;
+	short tac; /*2 bytes. 36.413: 9.2.3.7*/
+};
+
+struct STMSI {
+	uint8_t mme_code;
+    uint32_t m_TMSI;
+};
+
+
+typedef struct tai_list {
+	uint8_t spare :1;
+	uint8_t type :2;
+	uint8_t num_of_elements :4;
+	struct TAI partial_list[EMM_MAX_TAI_LIST];
+} tai_list;
+
+typedef struct pdn_address {
+	uint8_t spare :5;
+	uint8_t type :3;
+	uint32_t ipv4; /* TODO: Revisit 24.301 - 9.9.4.9.1 */
+} pdn_address;
+
+typedef struct linked_transcation_id {
+	uint8_t flag :1;
+	uint8_t val :7;
+} linked_transcation_id;
+
+typedef struct esm_qos
+{
+	uint8_t reliability_class :3;
+	uint8_t delay_class :3;
+	uint8_t spare1 :2;
+	uint8_t precedence_class :3;
+	uint8_t spare2 :1;
+	uint8_t peak_throughput :4;
+	uint8_t mean_throughput :5;
+	uint8_t spare3 :3;
+	uint8_t delivery_err_sdu :3;
+	uint8_t delivery_order :2;
+	uint8_t traffic_class :3;
+	uint8_t max_sdu_size;
+	uint8_t mbr_ul;
+	uint8_t mbr_dl;
+	uint8_t sdu_err_ratio :4;
+	uint8_t residual_ber :4;
+	uint8_t trffic_prio :2;
+	uint8_t transfer_delay :6;
+	uint8_t gbr_ul;
+	uint8_t gbr_dl;
+	uint8_t src_stat_desc :4;
+	uint8_t sig_ind :1;
+	uint8_t spare4 :3;
+	uint8_t mbr_dl_ext;
+	uint8_t gbr_dl_ext;
+	uint8_t mbr_ul_ext;
+	uint8_t gbr_ul_ext;
+
+} esm_qos;
+
+/* TODO : Revisit 24.301 - 9.9.4.2.1 */
+typedef struct ESM_APN_AMBR {
+	uint8_t dl;
+	uint8_t reserved;
+	uint8_t dlext;
+	uint8_t ulext;
+	uint8_t dlext2;
+	/* uint8_t dl_total; */
+	uint8_t ulext2;
+	/* uint8_t ul_total; */
+} ESM_APN_AMBR;
+
+typedef struct guti {
+	uint8_t spare :4;
+	uint8_t odd_even_indication :1;
+	uint8_t id_type :3;
+	struct PLMN plmn_id;
+	uint16_t mme_grp_id;
+	uint8_t mme_code;
+	uint32_t m_TMSI;
+} guti;
+
+typedef struct esm_msg_container {
+	uint8_t eps_bearer_id :4;
+	uint8_t proto_discriminator :4;
+	uint8_t procedure_trans_identity;
+	uint8_t session_management_msgs;
+	uint8_t eps_qos;  /* TODO: Revisit 24.301 - 9.9.4.3.1 */
+	struct apn_name apn;
+	pdn_address pdn_addr;
+	linked_transcation_id linked_ti;
+	esm_qos negotiated_qos;
+	ESM_APN_AMBR apn_ambr;
+} esm_msg_container;
+
+typedef struct ue_sec_capabilities {
+	uint8_t eea1 :1;
+	uint8_t eea2 :1;
+	uint8_t eea3 :1;
+	uint8_t eea4 :1;
+	uint8_t eea5 :1;
+	uint8_t eea6_128 :1;
+	uint8_t eea7_128 :1;
+	uint8_t eea8 :1;
+
+	uint8_t eia1 :1;
+	uint8_t eia2 :1;
+	uint8_t eia3 :1;
+	uint8_t eia4 :1;
+	uint8_t eia5 :1;
+	uint8_t eia6_128 :1;
+	uint8_t eia8_128 :1;
+	uint8_t eia8 :1;
+
+	uint8_t uea1 :1;
+	uint8_t uea2 :1;
+	uint8_t uea3 :1;
+	uint8_t uea4 :1;
+	uint8_t uea5 :1;
+	uint8_t uea6 :1;
+	uint8_t uea7 :1;
+	uint8_t uea8 :1;
+
+	uint8_t uia1 :1;
+	uint8_t uia2 :1;
+	uint8_t uia3 :1;
+	uint8_t uia4 :1;
+	uint8_t uia5 :1;
+	uint8_t uia6 :1;
+	uint8_t uia7 :1;
+	uint8_t spare1 :1;
+
+	uint8_t gea1 :1;
+	uint8_t gea2 :1;
+	uint8_t gea3 :1;
+	uint8_t gea4 :1;
+	uint8_t gea5 :1;
+	uint8_t gea6 :1;
+	uint8_t gea7 :1;
+	uint8_t spare2 :1;
+} ue_sec_capabilities;
+
+typedef struct nas_pdu_header {
+	unsigned char security_header_type:4;
+	unsigned char proto_discriminator:4;
+	unsigned char message_type;
+	unsigned char security_encryption_algo:4;
+	unsigned char security_integrity_algo:4;
+	unsigned char nas_security_param;
+	unsigned char mac[MAC_SIZE];
+	unsigned char short_mac[SHORT_MAC_SIZE];
+	unsigned char ksi;
+	unsigned char seq_no;
+	unsigned char eps_bearer_identity;
+	unsigned char procedure_trans_identity;
+	unsigned char detach_type;
+} nas_pdu_header;
+
+#pragma pack()
+
+/****Information elements presentations **/
+#define BINARY_IMSI_LEN 8 /*same as packet capture. TODO: Write macros*/
+#define BCD_IMSI_STR_LEN 15
+
+/*36.413 - 9.2.1.38*/
+struct CGI {
+	struct PLMN plmn_id;
+	int cell_id;
+};
+/*36.413: 9.2.1.37*/
+#define MACRO_ENB_ID_SIZE 20
+struct ie_global_enb_id {
+	int plmn;
+	char macro_enb_id[MACRO_ENB_ID_SIZE];
+	/*TODO: make union of enb IDs*/
+};
+
+/*36.413: 9.1.8.4*/
+#define ENB_NAME_SIZE 150
+struct ie_enb_name {
+	char enb_name[ENB_NAME_SIZE];
+};
+
+/*36.413: 9.2.1.3a*/
+enum ie_RRC_est_cause {
+	EMERGENCY,
+	HIGHPRIORITYACCESS,
+	MT_ACCESS,
+	MO_SIGNALLING,
+	MO_DATA,
+	DELAYTOLERANTACCESS,
+	MO_VOICECALL,
+	MO_EXCEPTIONDATA
+};
+
+/**E-RAB structure declarations**/
+struct eRAB_header { //TODO: making provision, chec -is it needed?
+	unsigned char criticality;
+};
+
+struct eRAB_setup_ctx_SU {
+	unsigned short eRAB_id;
+	unsigned short dont_know_byte;
+	unsigned int transp_layer_addr;
+	unsigned int gtp_teid;
+};
+
+union eRAB_IE {
+	struct eRAB_setup_ctx_SU su_res;
+};
+
+typedef struct eRAB_elements {
+	struct eRAB_header header;
+	unsigned char no_of_elements;
+	union eRAB_IE *elements;
+}eRAB_elements;
+/**eRAB structures end**/
+
+/**Information elements structs end**/
+typedef union nas_pdu_elements_union {
+	unsigned char rand[NAS_RAND_SIZE];
+	unsigned char autn[NAS_AUTN_SIZE];
+	unsigned char IMSI[BINARY_IMSI_LEN];
+	unsigned char short_mac[SHORT_MAC_SIZE];
+	struct esm_sec_info esm_info;
+	enum drx_params drx;
+	struct MS_net_capab ms_network;
+	struct UE_net_capab ue_network;
+
+	struct XRES   auth_resp; /*Authentication response*/
+	struct AUTS   auth_fail_resp; /*Authentication response*/
+
+	struct apn_name apn;
+
+	unsigned char attach_res;
+	unsigned char t3412;
+	tai_list tailist;
+	esm_msg_container esm_msg;
+	guti mi_guti;
+	bool esm_info_tx_required;
+	unsigned char pti;
+    unsigned char eps_res;
+    unsigned char spare;
+    unsigned short int pco_options[10];
+}nas_pdu_elements_union;
+typedef struct nas_pdu_elements {
+   nas_ie_type msgType;
+   nas_pdu_elements_union pduElement;
+}nas_pdu_elements;
+
+
+#define NAS_MSG_UE_IE_GUTI  0x00000001
+#define NAS_MSG_UE_IE_IMSI  0x00000002
+#define UE_ID_IMSI(flags)   ((flags & NAS_MSG_UE_IE_IMSI) == NAS_MSG_UE_IE_IMSI)
+#define UE_ID_GUTI(flags)   ((flags & NAS_MSG_UE_IE_GUTI) == NAS_MSG_UE_IE_GUTI)
+typedef struct nasPDU {
+	nas_pdu_header header;
+	unsigned char elements_len;
+	nas_pdu_elements *elements;
+    unsigned int flags;
+} nasPDU;
+
+#pragma pack(1)
+/* TODO : Change type */
+typedef struct ue_aggregate_maximum_bitrate {
+	uint32_t uEaggregateMaxBitRateDL;
+	uint32_t uEaggregateMaxBitRateUL;
+} ue_aggregate_maximum_bitrate;
+
+typedef struct allocation_retention_prio {
+	uint8_t prioLevel :4;
+	uint8_t preEmptionCapab :1;
+	uint8_t preEmptionVulnebility :1;
+	uint8_t spare :2;
+} allocation_retention_prio;
+
+typedef struct E_RAB_Level_QoS_Params {
+	uint8_t qci;
+	//uint8_t ext;
+    allocation_retention_prio arPrio;
+} E_RAB_Level_QoS_Params;
+
+typedef struct ERABSetup {
+	uint8_t e_RAB_ID;
+	E_RAB_Level_QoS_Params e_RAB_QoS_Params;
+	uint32_t transportLayerAddress;
+	uint32_t gtp_teid;
+	struct nasPDU nas;
+} ERABSetup;
+
+#pragma pack()
+/* Dependencies */
+typedef enum s1apCause_PR {
+    s1apCause_PR_NOTHING,   /* No components present */
+    s1apCause_PR_radioNetwork,
+    s1apCause_PR_transport,
+    s1apCause_PR_nas,
+    s1apCause_PR_protocol,
+    s1apCause_PR_misc
+
+} s1apCause_PR;
+
+typedef enum s1apCause_PR_transporauseRadioNetwork {
+    s1apCauseRadioNetwork_unspecified   = 0,
+    s1apCauseRadioNetwork_tx2relocoverall_expiry    = 1,
+    s1apCauseRadioNetwork_successful_handover   = 2,
+    s1apCauseRadioNetwork_release_due_to_eutran_generated_reason    = 3,
+    s1apCauseRadioNetwork_handover_cancelled    = 4,
+    s1apCauseRadioNetwork_partial_handover  = 5,
+    s1apCauseRadioNetwork_ho_failure_in_target_EPC_eNB_or_target_system = 6,
+    s1apCauseRadioNetwork_ho_target_not_allowed = 7,
+    s1apCauseRadioNetwork_tS1relocoverall_expiry    = 8,
+    s1apCauseRadioNetwork_tS1relocprep_expiry   = 9,
+    s1apCauseRadioNetwork_cell_not_available    = 10,
+    s1apCauseRadioNetwork_unknown_targetID  = 11,
+    s1apCauseRadioNetwork_no_radio_resources_available_in_target_cell   = 12,
+    s1apCauseRadioNetwork_unknown_mme_ue_s1ap_id    = 13,
+    s1apCauseRadioNetwork_unknown_enb_ue_s1ap_id    = 14,
+    s1apCauseRadioNetwork_unknown_pair_ue_s1ap_id   = 15,
+    s1apCauseRadioNetwork_handover_desirable_for_radio_reason   = 16,
+    s1apCauseRadioNetwork_time_critical_handover    = 17,
+    s1apCauseRadioNetwork_resource_optimisation_handover    = 18,
+    s1apCauseRadioNetwork_reduce_load_in_serving_cell   = 19,
+    s1apCauseRadioNetwork_user_inactivity   = 20,
+    s1apCauseRadioNetwork_radio_connection_with_ue_lost = 21,
+    s1apCauseRadioNetwork_load_balancing_tau_required   = 22,
+    s1apCauseRadioNetwork_cs_fallback_triggered = 23,
+    s1apCauseRadioNetwork_ue_not_available_for_ps_service   = 24,
+    s1apCauseRadioNetwork_radio_resources_not_available = 25,
+    s1apCauseRadioNetwork_failure_in_radio_interface_procedure  = 26,
+    s1apCauseRadioNetwork_invalid_qos_combination   = 27,
+    s1apCauseRadioNetwork_interrat_redirection  = 28,
+    s1apCauseRadioNetwork_interaction_with_other_procedure  = 29,
+    s1apCauseRadioNetwork_unknown_E_RAB_ID  = 30,
+    s1apCauseRadioNetwork_multiple_E_RAB_ID_instances   = 31,
+    s1apCauseRadioNetwork_encryption_and_or_integrity_protection_algorithms_not_supported   = 32,
+    s1apCauseRadioNetwork_s1_intra_system_handover_triggered    = 33,
+    s1apCauseRadioNetwork_s1_inter_system_handover_triggered    = 34,
+    s1apCauseRadioNetwork_x2_handover_triggered = 35,
+    s1apCauseRadioNetwork_redirection_towards_1xRTT = 36,
+    s1apCauseRadioNetwork_not_supported_QCI_value   = 37,
+    s1apCauseRadioNetwork_invalid_CSG_Id    = 38,
+    s1apCauseRadioNetwork_release_due_to_pre_emption    = 39
+} e_s1apCauseRadioNetwork;
+
+typedef enum s1apCauseTransport {
+    s1apCauseTransport_transport_resource_unavailable   = 0,
+    s1apCauseTransport_unspecified  = 1
+} e_s1apCauseTransport;
+
+typedef enum s1apCauseNas {
+    s1apCauseNas_normal_release = 0,
+    s1apCauseNas_authentication_failure = 1,
+    s1apCauseNas_detach = 2,
+    s1apCauseNas_unspecified    = 3,
+    s1apCauseNas_csg_subscription_expiry    = 4
+} e_s1apCauseNas;
+
+typedef enum s1apCauseProtocol {
+    s1apCauseProtocol_transfer_syntax_error = 0,
+    s1apCauseProtocol_abstract_syntax_error_reject  = 1,
+    s1apCauseProtocol_abstract_syntax_error_ignore_and_notify   = 2,
+    s1apCauseProtocol_message_not_compatible_with_receiver_state    = 3,
+    s1apCauseProtocol_semantic_error    = 4,
+    s1apCauseProtocol_abstract_syntax_error_falsely_constructed_message = 5,
+    s1apCauseProtocol_unspecified   = 6
+} e_s1apCauseProtocol;
+
+typedef enum s1apCauseMisc {
+    s1apCauseMisc_control_processing_overload   = 0,
+    s1apCauseMisc_not_enough_user_plane_processing_resources    = 1,
+    s1apCauseMisc_hardware_failure  = 2,
+    s1apCauseMisc_om_intervention   = 3,
+    s1apCauseMisc_unspecified   = 4,
+    s1apCauseMisc_unknown_PLMN  = 5
+} e_s1apCauseMisc;
+
+/* s1apCauseMisc */
+typedef long     s1apCauseMisc_t;
+/* s1apCauseProtocol */
+typedef long     s1apCauseProtocol_t;
+/* s1apCauseNas */
+typedef long     s1apCauseNas_t;
+/* s1apCauseTransport */
+typedef long     s1apCauseTransport_t;
+/* s1apCauseRadioNetwork */
+typedef long     s1apCauseRadioNetwork_t;
+
+typedef struct s1apCause {
+    s1apCause_PR present;
+    union s1apCause_u {
+        s1apCauseRadioNetwork_t  radioNetwork;
+        s1apCauseTransport_t     transport;
+        s1apCauseNas_t   nas;
+        s1apCauseProtocol_t  protocol;
+        s1apCauseMisc_t  misc;
+    } choice;
+} s1apCause_t;
+
+
+typedef struct proto_IE_data {
+	int 			IE_type;
+    union value{
+        struct ie_enb_name 	enb_name;
+        struct ie_global_enb_id global_enb_id;
+        long			enb_ue_s1ap_id;
+        long			mme_ue_s1ap_id;
+        struct 			nasPDU nas;
+        struct s1apCause cause;
+        struct TAI 		 tai;
+        struct CGI 		 utran_cgi;
+        struct STMSI	 s_tmsi;
+        enum ie_RRC_est_cause 	rrc_est_cause;
+        struct eRAB_elements 	erab;
+        ue_aggregate_maximum_bitrate ue_aggrt_max_bit_rate;
+        ERABSetup E_RABToBeSetupItemCtxtSUReq;
+        ue_sec_capabilities ue_sec_capab;
+        uint8_t sec_key[SECURITY_KEY_SIZE];
+    }val;
+}proto_IEs;
+
+struct proto_IE {
+    ProcedureCode_t  procedureCode;
+    Criticality_t    criticality;
+	short 		no_of_IEs;
+	proto_IEs	*data;
+	uint8_t     ie_nas_index;
+    uint8_t     ie_tai_index;
+    uint8_t     ie_cgi_index;
+};
+
+enum protocolie_id {
+	id_MME_UE_S1AP_ID = 0,
+	id_Cause = 2,
+	id_eNB_UE_S1AP_ID = 8,
+	id_ERABToBeSetupListCtxtSUReq = 24,
+	id_NAS_PDU = 26,
+	id_ERABToBeSetupItemCtxtSUReq = 52,
+	id_uEaggregatedMaximumBitrate = 66,
+	id_SecurityKey = 73,
+	id_UE_S1AP_IDs = 99,
+	id_UESecurityCapabilities = 107,
+};
+
+enum protocol_discriminator{
+	EPSSessionManagementMessage = 2,
+    EPSMobilityManagementMessages = 7,
+};
+
+enum criticality{
+	CRITICALITY_REJECT = 0x0,
+	CRITICALITY_IGNORE = 0x40,
+	CRITICALITY_NOTIFY,
+};
+
+enum eps_nas_mesage_type {
+	AttachAccept = 0x42,
+	AttachReject = 0x44,
+	DetachAccept = 0x46,
+	DetachRequest = 0x45,
+	TauAccept    = 0x49,
+    TauReject    = 0x4b,
+	AuthenticationRequest = 0x52,
+    IdentityRequest       = 0x55,
+	SecurityModeCommand = 0x5d,
+	ESMInformationRequest = 0xd9,
+};
+
+enum procedure_code {
+	id_InitialContextSetup = 9,
+	id_downlinkNASTransport = 11,
+	id_errorIndication = 15,
+	id_UEContexRelease = 23,
+};
+
+typedef struct s1ap_PDU {
+	unsigned char procedurecode;
+	unsigned char criticality;
+	struct proto_IE value;
+}s1ap_PDU;
+
+/* NAS Security Header */
+typedef enum security_header_type {
+    Plain = 0,
+    IntegrityProtected,
+    IntegrityProtectedCiphered,
+    IntegrityProtectedEPSSecCntxt,
+}security_header_type;
+
+typedef struct nas_pdu_header_sec {
+        unsigned char security_header_type:4;
+        unsigned char proto_discriminator:4;
+        unsigned char mac[MAC_SIZE];
+        unsigned char seq_no;
+}nas_pdu_header_sec;
+
+typedef struct nas_pdu_header_short {
+        unsigned char security_header_type:4;
+        unsigned char proto_discriminator:4;
+        unsigned char message_type;
+}nas_pdu_header_short;
+
+typedef struct nas_pdu_header_long {
+        unsigned char security_header_type:4;
+        unsigned char proto_discriminator:4;
+        unsigned char procedure_trans_identity;
+        unsigned char message_type;
+}nas_pdu_header_long;
+
+/* NAS Security Encryption Algorithm */
+typedef enum security_encryption_algo {
+	Algo_EEA0 = 0,
+
+}security_encryption_algo;
+
+/* NAS Security Integrity Algorithm */
+typedef enum security_integrity_algo {
+	Algo_EIA0 = 0,
+	Algo_128EIA1 = 1,
+}security_integrity_algo;
+
+
+#define BUFFER_SIZE 255
+
+typedef struct Buffer {
+	unsigned char buf[BUFFER_SIZE];
+	unsigned char pos;
+}Buffer;
+
+#endif /*__S1AP_STRUCTS_H*/
diff --git a/include/common/sec.h b/include/common/sec.h
new file mode 100644
index 0000000..845c2d8
--- /dev/null
+++ b/include/common/sec.h
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+
+#ifndef __STAGE1_SEC_H_
+#define __STAGE1_SEC_H_
+
+/* Common to HSS and MME */
+#define AIA_RES_SIZE         8
+#define AIA_AUTS_SIZE        14
+#define AIA_AUTN_SIZE        16
+#define AIA_RAND_SIZE        16
+#define AIA_KASME_SIZE       32
+#define AIA_NEXT_HOP_SIZE    32
+
+#define HASH_SALT_LEN        7
+#define HASH_KEY_LEN         512
+
+#define NAS_INT_KEY_SIZE     16
+#define KENB_SIZE            32
+#define HMAC_SIZE            1024
+
+typedef struct RAND {
+	unsigned char len;
+	unsigned char val[AIA_RAND_SIZE];
+} RAND;
+
+typedef struct XRES {
+	unsigned char len;
+	unsigned char val[AIA_RES_SIZE];
+} XRES;
+
+typedef struct AUTS {
+	unsigned char len;
+	unsigned char val[AIA_AUTS_SIZE];
+} AUTS;
+
+typedef struct AUTN {
+	unsigned char len;
+	unsigned char val[AIA_AUTN_SIZE];
+} AUTN;
+
+typedef struct KASME {
+	unsigned char len;
+	unsigned char val[AIA_KASME_SIZE];
+} KASME;
+
+/**
+ * @brief Create integrity key
+ * @param[in] kasme key
+ * @param[out] int_key generated integrity key
+ * @return void
+ */
+void create_integrity_key(unsigned char *kasme, unsigned char *int_key);
+
+/**
+ * @brief Create eNodeB key to exchange in init ctx message
+ * @param [in]kasme key
+ * @param [out]kenb_key output the generated key
+ * @return void
+ */
+void create_kenb_key(unsigned char *kasme, unsigned char *kenb_key,
+		unsigned int seq_no);
+
+
+void calculate_hmac_sha256(const unsigned char *input_data,
+	    int input_data_len, const unsigned char *key,
+		int key_length, void *output, unsigned int *out_len);
+
+#endif
diff --git a/include/common/snow_3g.h b/include/common/snow_3g.h
new file mode 100644
index 0000000..fe2e8d4
--- /dev/null
+++ b/include/common/snow_3g.h
@@ -0,0 +1,44 @@
+/*---------------------------------------------------------
+* SNOW_3G.h
+*---------------------------------------------------------*/
+/*
+ * The code has been referred from
+ * 1. https://www.gsma.com/aboutus/wp-content/uploads/2014/12/snow3gspec.pdf
+ * 2. https://www.gsma.com/aboutus/wp-content/uploads/2014/12/uea2uia2d1v21.pdf
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+
+typedef unsigned char u8;
+typedef unsigned int u32;
+typedef unsigned long long u64;
+
+/* Initialization.
+ * Input k[4]: Four 32-bit words making up 128-bit key.
+ * Input IV[4]: Four 32-bit words making 128-bit initialization variable.
+ * Output: All the LFSRs and FSM are initialized for key generation.
+ * See Section 4.1 of
+ * (https://www.gsma.com/aboutus/wp-content/uploads/2014/12/snow3gspec.pdf)
+ * specs document.
+ */
+
+
+void Initialize(u32 k[4], u32 IV[4]);
+
+/* Generation of Keystream.
+* input n: number of 32-bit words of keystream.
+* input z: space for the generated keystream, assumes
+* memory is allocated already.
+* output: generated keystream which is filled in z
+* See section 4.2 of
+* (https://www.gsma.com/aboutus/wp-content/uploads/2014/12/snow3gspec.pdf)
+* specs document.
+*/
+
+void GenerateKeystream(u32 n, u32 *z);
+
diff --git a/include/common/stimer.h b/include/common/stimer.h
new file mode 100644
index 0000000..ddf65dc
--- /dev/null
+++ b/include/common/stimer.h
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+#ifndef __STIMER_H
+#define __STIMER_H
+
+#include <time.h>
+
+typedef long long int stimer_t;
+
+#define STIMER_GET_CURRENT_TP(__now__)                                                 \
+({                                                                                     \
+   struct timespec __ts__;                                                             \
+   __now__ = clock_gettime(CLOCK_REALTIME,&__ts__) ?                                   \
+         -1 : (((stimer_t)__ts__.tv_sec) * 1000000000) + ((stimer_t)__ts__.tv_nsec);   \
+   __now__;                                                                            \
+})
+
+#define STIMER_GET_ELAPSED_NS(_start_)                                                 \
+({                                                                                     \
+   stimer_t __ns__;                                                                    \
+   STIMER_GET_CURRENT_TP(__ns__);                                                      \
+   if (__ns__ != -1)                                                                   \
+      __ns__ -= _start_;                                                               \
+   __ns__;                                                                             \
+})
+
+#define STIMER_GET_ELAPSED_US(__start__)                                               \
+({                                                                                     \
+   stimer_t __us__ = STIMER_GET_ELAPSED_NS(__start__);                                 \
+   if (__us__ != -1)                                                                   \
+      __us__ = (__us__ / 1000) + (__us__ % 1000 >= 500 ? 1 : 0);                       \
+   __us__;                                                                             \
+})
+
+#define STIMER_GET_ELAPSED_MS(___start___)                                             \
+({                                                                                     \
+   stimer_t __ms__ = STIMER_GET_ELAPSED_US(___start___);                               \
+   if (__ms__ != -1)                                                                   \
+      __ms__ = (__ms__ / 1000) + (__ms__ % 1000 >= 500 ? 1 : 0);                       \
+   __ms__;                                                                             \
+})
+
+#endif
+
diff --git a/include/common/thread_pool.h b/include/common/thread_pool.h
new file mode 100644
index 0000000..0bbad0b
--- /dev/null
+++ b/include/common/thread_pool.h
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+#ifndef __THREAD_POOL_H
+#define __THREAD_POOL_H
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+struct thread_pool;
+typedef void (* JobFunction) (void *);
+
+/*
+ * Creates new thread pool
+ * on success return pointer to thread_pool
+ * on failure return NULL
+ */
+extern struct thread_pool *thread_pool_new(int count);
+
+/*
+ * Stops all threads and
+ * destroy the thread pool
+ * on success return 0
+ * on failure return -1
+ */
+extern int thread_pool_destroy(struct thread_pool *pool);
+
+/*
+ * Queues the job to thread pool
+ * idle threads will pick the job
+ * on success it return 0
+ * on failure returns -ve values
+ */
+extern int insert_job(struct thread_pool *pool, JobFunction function,
+		void *userdata);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/include/common/tpool_queue.h b/include/common/tpool_queue.h
new file mode 100644
index 0000000..9ebd3f3
--- /dev/null
+++ b/include/common/tpool_queue.h
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+
+#ifndef __TPOOL_QUEUE_H
+#define __TPOOL_QUEUE_H
+
+struct node {
+	void *data;
+	struct node *next;
+};
+
+struct Queue {
+	int length;
+	struct node *head;
+	struct node *tail;
+};
+
+struct thread_pool {
+	struct Queue *thread_queue;	/* queue to store thread ids */
+	struct Queue *job_queue;	/* for storing jobs */
+
+	pthread_mutex_t queue_mutex;	/* protection to job_queue */
+	pthread_cond_t job_received;	/* synchronisation with worker threads */
+	
+	pthread_t dispatch_thread;	/* signals threads if new work in job_queue*/
+
+	int idle_threads;		/* count of idle threads */
+};
+
+struct Job {
+	JobFunction function;
+	void *arg;
+};
+
+struct Queue;
+
+typedef void (* QueueDataFreeFunc)(void *data);
+
+extern struct Queue *queue_new();
+extern void queue_destroy(struct Queue *queue, QueueDataFreeFunc function);
+
+extern int queue_push_tail(struct Queue *queue, void *data);
+extern void *queue_pop_head(struct Queue *queue);
+extern int queue_get_length(struct Queue *queue);
+
+#endif
+